Multiple resize

See all posts Reply

Multiple resize new!
by Erwin, 16 years, 10 months ago
Hi,

I want to do the following:
- Save the original image;
- Save a version that has a x of 400;
- Save a version that has a x of 102.

I tried this but then i get a memory error.

How can i do this the good way?

This i what i tried:
include("class.upload.php");

if(isset($_POST['Submit'])) {
$foo = new Upload($_FILES['image_field']); 
if ($foo->uploaded) {
  // save uploaded image with no changes
  $foo->Process('creaties/');
  if ($foo->processed) { 
    echo 'original image copied'; 
  } else {
    echo 'error : ' . $foo->error;
  }
  // save uploaded image with a new name
  $foo->file_new_name_body = 'image_resized';
  $foo->image_resize = true;
  $foo->image_convert = gif;
  $foo->image_x = 400;
  $foo->image_ratio_y = true;
  $foo->Process('creaties/');
  if ($foo->processed) {
    echo 'image renamed, resized x=100 
          and converted to GIF';
    $foo->Clean();
  } else {
    echo 'error : ' . $foo->error;
  }
  // save uploaded image with a new name,
  // resized to 100px wide
  $foo->file_new_name_body = 'image_resized';
  $foo->image_resize = true;
  $foo->image_convert = gif;
  $foo->image_x = 100;
  $foo->image_ratio_y = true;
  $foo->Process('creaties/');
  if ($foo->processed) {
    echo 'image renamed, resized x=100 
          and converted to GIF';
    $foo->Clean();
  } else {
    echo 'error : ' . $foo->error;
  }
}
}

Thx, ErwinReply
Re: Multiple resize new!
by colin, 16 years, 10 months ago
The code looks OK (I haven't tested it, but it seems correct).

For the memory, PHP is probably running out of memory.

See this thread

Try to raise your local memory to 20M, 32M or more.

You can add this in your script:
ini_set ( "memory_limit", "20M")

Or in a .htaccess file:
php_value memory_limit 20M
Reply