aurigma conditional resize

203 Views Asked by At

Hello I am using a java based image uploader called aurigma, and setting it up using php code.

I have some resizing options that can be set on width or height.

I want to do a check where I say:

If ((image I am uploading width) > (image I am uploading height)){
   $converter->setThumbnailFitMode("Width");
}else{
   $converter->setThumbnailFitMode("Height");
}

How do I check the file size that I am uploading to aurigma and set conditions based on this. i.e.

2

There are 2 best solutions below

0
On
0
On

If you need to set converters in runtime you will need to set two extra events of aurigma uploader: 1.BeforeUpload and 2. BeforePackageUpload:

  uploader = new Uploader('Uploader1');
    ...
    $uploader->getClientEvents()->setBeforeUpload("BeforeUpload");
    $uploader->getClientEvents()->setBeforePackageUpload("BeforePackageUpload");
    ...

Then implement the code of events in Javascript block (script type = "text/javascript").

You will need to get widths and heights of all the images added to the upload pane and put these values to arrays. In BeforePackageUpload you should take values of width and height of each file and compare them to set needed converter fit mode:

//set new arrays 
var widths = [];
var heights = [];

function BeforeUpload() {
  var uploader = $au.uploader('Uploader1');
  count = uploader.files().count();
  for (i = 0; i < count; i++) {
    widths[i] = uploader.files().get(i).width();
    heights[i] = uploader.files().get(i).height();
  }
}

function BeforePackageUpload(index) {
  var uploader = $au.uploader('Uploader1');
  if (widths.shift() > heights.shift()) {
    uploader.converters([{
      mode: '*.*=Thumbnail',
      thumbnailFitMode: 'Width',
      thumbnailWidth: 500,
      thumbnailHeight: 300,
      thumbnailJpegQuality: 100
    }]);
  }

  else  
  {
    uploader.converters([{
      mode: '*.*=Thumbnail',
      thumbnailFitMode: 'Height',
      thumbnailWidth: 300,
      thumbnailHeight: 500,
      thumbnailJpegQuality: 100
    }]);
  }
}