2

I am trying to resize images after upload. I have 2 files(view_project.php and user.inc.php).
In user.inc.php I am uploading images and returning an array with names of the uploaded files.
In view_project.php I am getting that array and in foreach I am trying to resize images to 20% or 60% of resolution of original image.

It absolutely doesn't work. Images are uploaded on server but not resized.

  foreach($upload as $images_to_resize) {
      $file = ''.showConfigValues("img_source_admin").'/'.$images_to_resize; 

      $src = realpath($file);
      $dst = realpath($file); 
      $crop = false;

         list($old_w,$old_h) = getimagesize($file);

       if($old_w >= 1700 && $old_h >= 900) {

        $w = floor(($old_w / 100) * 20);
        $h = floor(($old_h / 100) * 20);
       }
        else {
         $w = floor(($old_w / 100) * 60);
         $h = floor(($old_h / 100) * 60);  
        }
          $picture = new Imagick($src);

          $picture->setImageResolution(300,300);
          autoRotateImage($picture); 
          $picture->resizeImage(684, 457, Imagick::FILTER_LANCZOS,1, false);
          $picture->writeImage($cropped);
          $picture->clear();
          $picture->destroy();

     }

I really need your help. Thanks

ViktorR
  • 137
  • 3
  • 13

1 Answers1

0

This might be an easy one: I don't see where you have defined "$cropped".

That variable should be defined, it should be a unique value for each image in the array, and it should also contain the file extension. For example:

foreach($upload as $key => $images_to_resize) {
    $fileName = $_FILES["upload"]["tmp_name"][$key]
    $cropped = 'resized_'.$fileName;
    ...
    $picture->writeImage($cropped.'.jpg');
    ...

I added $key to your foreach to help pull the temporary filename from the $_FILES array and reuse it.

I never use the autorotate command, but it looks as if it doesn't fit the object format. Try:

$picture->autoRotateImage($picture); 

You may also want to test your imagemagick installation and php plugin:

Verify ImageMagick installation

Parapluie
  • 714
  • 1
  • 7
  • 22