Instead of giving users the option of creating a thumbnail or resizing the image, I want to create several files every time an image is uploaded (icon, thumb, small, large).

Has this been done before? Any suggestions on the easiest way to do it?

I've added...

//thumbnails
//SMALL
imce_resize_image($set, basename($newpath), 200, 200, TRUE);
//THUMB
imce_resize_image($set, basename($newpath), 50, 50, TRUE);
if ($_POST['thumb']....

Which seems to work, but I'm wondering if I'm going to run into problems I'm not seeing.

Comments

ufku’s picture

Yours is the ideal way to preserve user limitations. Direct resizing could be faster however nothing will be checked regarding user settings.

kreynen’s picture

Oh how I long for the day code will do what I want instead of what I say!?!

That was creating the new thumbnails exactly how I was telling it to... 50x50, 200x200 regardless of the aspect of the original. Now I realize that the aspect is determined before the imce_resize_image is called... not in that function.

This works much better...

//thumbnails
//ICON
$aspect = $info[1] / $info[0];

if ($aspect < $set->theight / $set->twidth) {
$w = (int)min($set->twidth, 50);
$h = (int)round($w * $aspect);
}
else {
$h = (int)min($set->theight, 50);
$w = (int)round($h / $aspect);
}
imce_resize_image($set, basename($newpath), $w, $h, TRUE);
//THUMB

if ($aspect < $set->theight / $set->twidth) {
$w = (int)min($set->twidth, 100);
$h = (int)round($w * $aspect);
}
else {
$h = (int)min($set->theight, 100);
$w = (int)round($h / $aspect);
}

imce_resize_image($set, basename($newpath), $w, $h, TRUE);
//SMALL

if ($aspect < $set->theight / $set->twidth) {
$w = (int)min($set->twidth, 250);
$h = (int)round($w * $aspect);
}
else {
$h = (int)min($set->theight, 250);
$w = (int)round($h / $aspect);
}

imce_resize_image($set, basename($newpath), $w, $h, TRUE);

//LARGE
if ($aspect < $set->theight / $set->twidth) {
$w = (int)min($set->twidth, 500);
$h = (int)round($w * $aspect);
}
else {
$h = (int)min($set->theight, 500);
$w = (int)round($h / $aspect);
}

imce_resize_image($set, basename($newpath), $w, $h, TRUE);

ufku’s picture

to prevent duplicate code use an array of thumbnail sizes and loop over it.

  $thumbs = array(array(50, 50), array(100, 100), array(250, 250));
  $aspect = $info[1] / $info[0];
  foreach ($thumbs as $thumb) {
    if ($aspect < $thumb[1] / $thumb[0]) {
      $w = (int)min($thumb[0], $info[0]);
      $h = (int)round($w * $aspect);
    }
    else {
      $h = (int)min($thumb[1], $info[1]);
      $w = (int)round($h / $aspect);
    }
    imce_resize_image($set, basename($newpath), $w, $h, TRUE);
  }
newdru’s picture

i'm interested in this functionality.

Where would code be patched in and in what file? if someone could explain that it would be great!

thanks

ufku’s picture

it's the thumbnail creation part line #306

summit’s picture

Will this patch go in?
greetings,
Martijn

ufku’s picture

Status: Active » Closed (fixed)