cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Sparkes <pe...@didm.co.uk>
Subject Resizing images using imgscalr
Date Thu, 18 Sep 2014 13:43:30 GMT
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



Mime
View raw message