You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Peter Sparkes <pe...@didm.co.uk> on 2014/09/18 15:43:30 UTC

Resizing images using imgscalr

Hi,

Cocoon 2.1.12

  I use the following javascript ( Text in Black )with the Cocoon "Upload widget" uploading images 
to the upload-dir and then move them to the "lodgeimage300px" directory. This works

I now want to scale the images using imgscalr , 
http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/#source

I, therefore, added the code in red

The BufferedImage   in BufferedImage scaledImage =Scalr.resize(file, 200); gave me a syntax error.

On removing BufferedImage   I get the following error "Scalr" is not defined

Can anyone help me Please

Peter

importClass(Packages.java.io.File);
importClass(Packages.java.io.FileOutputStream);
importClass(Packages.java.io.FileNotFoundException);

importClass(org.imgscalr.Scalr);
importClass(Packages.java.awt.image.BufferedImage);
importClass(Packages.javax.imageio.ImageIO);

function uploadprogress() {

     var form = new Form("forms/uploadprogress_model.xml");
     form.setAttribute("counter", new java.lang.Integer(0));
     var k = form.showForm("uploadprogress-display-pipeline.jx");

     //var fileSource = "D:/cocoon-2.1.11-wl/build/webapp/upload-dir/"; //for testing
     var fileSource = "/usr/share/tomcat7/instances/chinese-dev/webapps/ROOT/upload-dir/";

     //var fileTarget = "D:/cocoon-2.1.11-wl/build/webapp/resources/imagesSmall/"; //for testing
     var fileTarget = 
"/usr/share/tomcat7/instances/chinese-dev/webapps/ROOT/resources/lodgeimages300px/";


     var fileSourcePath = "";
     var fileTargetPath = "";
     var file = "";

var resizedTargetPath = 
"/usr/local/tomcat/instances/chinese-dev/webapps/ROOT/resources/lodgeimagesSmall/";
     var resizedfileTargetPath = resizedTargetPath+"test.jpg";
     var scaledImage = "";

     k.invalidate(); // do not allow return to the form

         var files = [];
         var repeater = form.getChild("uploads");
         for (var i = 0; i < repeater.getSize(); i++) {
             var upload = repeater.getRow(i).getChild("upload");
             files[i] = {
                 filename: upload.value.fileName,
                 bytes: upload.value.size
             };
            fileSourcePath = fileSource + upload.value.fileName;
            fileTargetPath = fileTarget + upload.value.fileName;
            file = new File(fileSourcePath);
            file.renameTo(new File(fileTargetPath));

   BufferedImage scaledImage =Scalr.resize(file, 200);



         }
     cocoon.sendPage("upload-images-success.jx",
         {
             files: files
         }
     );
}



I now want to extend uploadprogress() to scale the images before moving them to their target 
directory using

  " imgscalr", http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/#source



Re: Resizing images using imgscalr

Posted by Sandor Szatmari <ad...@gmail.com>.
Yes, I would second my own recommendation for using JAI.  It works great for this.  I store large TIFF images in Postgres as blobs and scale them on the fly based on the HTTP request params.  I have fixed sizes, like thumbnail, and info, but also support support arbitrary sizes.  Only specify x, or y and the scaling is proportional.

Sandor Szatmari

> On Sep 24, 2014, at 09:31, Thorsten Scherler <th...@apache.org> wrote:
> 
>> On 18/09/14 15:43, Peter Sparkes wrote:
>> Hi,
>> 
>> Cocoon 2.1.12
>> 
>>  I use the following javascript ( Text in Black )with the Cocoon "Upload widget" uploading images to the upload-dir and then move them to the "lodgeimage300px" directory. This works
>> 
>> I now want to scale the images using imgscalr , http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/#source
>> 
>> I, therefore, added the code in red
>> 
>> The BufferedImage   in BufferedImage scaledImage =Scalr.resize(file, 200); gave me a syntax error.
>> 
>> On removing  BufferedImage   I get the following error "Scalr" is not defined
>> 
>> Can anyone help me Please
>> 
>> Peter
>> 
>> importClass(Packages.java.io.File);
>> importClass(Packages.java.io.FileOutputStream);
>> importClass(Packages.java.io.FileNotFoundException);
>> 
>> importClass(org.imgscalr.Scalr);
> 
> This does not have the "importClass(Packages." prefix that explains why later this class is not defiened. However I personally would solve that with java.
> 
> salu2
> -- 
> Thorsten Scherler <thorsten.at.apache.org>
> codeBusters S.L. - web based systems
> <consulting, training and solutions>
> http://www.codebusters.es/

Re: Resizing images using imgscalr

Posted by Peter Sparkes <pe...@didm.co.uk>.
Hi

The importClass(Packages.problem has been fixed.

I now get the following error

org.mozilla.javascript.EvaluatorException: 
"file:///usr/share/tomcat7/instances/chinese-dev/webapps/ROOT/office/flow/upload_example.js", line 
103: Can't find method org.imgscalr.Scalr.resize(java.awt.image.BufferedImage,java.lang.Integer).

The problem I have is that I am not a java programmer

Regards

Petere


On 24/09/2014 14:31, Thorsten Scherler wrote:
> On 18/09/14 15:43, Peter Sparkes wrote:
>> Hi,
>>
>> Cocoon 2.1.12
>>
>>  I use the following javascript ( Text in Black )with the Cocoon "Upload widget" uploading images 
>> to the upload-dir and then move them to the "lodgeimage300px" directory. This works
>>
>> I now want to scale the images using imgscalr , 
>> http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/#source
>>
>> I, therefore, added the code in red
>>
>> The BufferedImage   in BufferedImage scaledImage =Scalr.resize(file, 200); gave me a syntax error.
>>
>> On removing BufferedImage   I get the following error "Scalr" is not defined
>>
>> Can anyone help me Please
>>
>> Peter
>>
>> importClass(Packages.java.io.File);
>> importClass(Packages.java.io.FileOutputStream);
>> importClass(Packages.java.io.FileNotFoundException);
>>
>> importClass(org.imgscalr.Scalr);
>
> This does not have the "importClass(Packages." prefix that explains why later this class is not 
> defiened. However I personally would solve that with java.
>
> salu2
> -- 
> Thorsten Scherler <thorsten.at.apache.org>
> codeBusters S.L. - web based systems
> <consulting, training and solutions>
> http://www.codebusters.es/


Re: Resizing images using imgscalr

Posted by Thorsten Scherler <th...@apache.org>.
On 18/09/14 15:43, Peter Sparkes wrote:
> Hi,
>
> Cocoon 2.1.12
>
>  I use the following javascript ( Text in Black )with the Cocoon 
> "Upload widget" uploading images to the upload-dir and then move them 
> to the "lodgeimage300px" directory. This works
>
> I now want to scale the images using imgscalr , 
> http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/#source
>
> I, therefore, added the code in red
>
> The BufferedImage   in BufferedImage scaledImage =Scalr.resize(file, 
> 200); gave me a syntax error.
>
> On removing BufferedImage   I get the following error "Scalr" is not 
> defined
>
> Can anyone help me Please
>
> Peter
>
> importClass(Packages.java.io.File);
> importClass(Packages.java.io.FileOutputStream);
> importClass(Packages.java.io.FileNotFoundException);
>
> importClass(org.imgscalr.Scalr);

This does not have the "importClass(Packages." prefix that explains why 
later this class is not defiened. However I personally would solve that 
with java.

salu2

-- 
Thorsten Scherler <thorsten.at.apache.org>
codeBusters S.L. - web based systems
<consulting, training and solutions>
http://www.codebusters.es/