Page 1 of 1

Image resizing SimpleImage.php, resolution problem?

Posted: Fri Apr 22, 2011 2:43 pm
by defroster
Hello,

I am including file SimpleImage.php in my php file. The script will handle everything perfectly, but if I try and upload a very large resolution image 2560x1440 the script just dies and no resizing is made. The file size of the high resolution image is well below 2 Mb, so there is no file size issue. I am troubled. Any ideas? Thanks.

SimpleImage.php

Code: Select all

<?php
/*
* File: SimpleImage.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 08/11/06
* Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php
* 
* This program is free software; you can redistribute it and/or 
* modify it under the terms of the GNU General Public License 
* as published by the Free Software Foundation; either version 2 
* of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful, 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
* GNU General Public License for more details: 
* http://www.gnu.org/licenses/gpl.html
*
*/
 
class SimpleImage {
   
   var $image;
   var $image_type;
 
   function load($filename) {
      $image_info = getimagesize($filename);
      $this->image_type = $image_info[2];
      if( $this->image_type == IMAGETYPE_JPEG ) {
         $this->image = imagecreatefromjpeg($filename);
      } elseif( $this->image_type == IMAGETYPE_GIF ) {
         $this->image = imagecreatefromgif($filename);
      } elseif( $this->image_type == IMAGETYPE_PNG ) {
         $this->image = imagecreatefrompng($filename);
      }
   }
   function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
      if( $image_type == IMAGETYPE_JPEG ) {
         imagejpeg($this->image,$filename,$compression);
      } elseif( $image_type == IMAGETYPE_GIF ) {
         imagegif($this->image,$filename);         
      } elseif( $image_type == IMAGETYPE_PNG ) {
         imagepng($this->image,$filename);
      }   
      if( $permissions != null) {
         chmod($filename,$permissions);
      }
   }
   function output($image_type=IMAGETYPE_JPEG) {
      if( $image_type == IMAGETYPE_JPEG ) {
         imagejpeg($this->image);
      } elseif( $image_type == IMAGETYPE_GIF ) {
         imagegif($this->image);         
      } elseif( $image_type == IMAGETYPE_PNG ) {
         imagepng($this->image);
      }   
   }
   function getWidth() {
      return imagesx($this->image);
   }
   function getHeight() {
      return imagesy($this->image);
   }
   function resizeToHeight($height) {
      $ratio = $height / $this->getHeight();
      $width = $this->getWidth() * $ratio;
      $this->resize($width,$height);
   }
   function resizeToWidth($width) {
      $ratio = $width / $this->getWidth();
      $height = $this->getheight() * $ratio;
      $this->resize($width,$height);
   }
   function scale($scale) {
      $width = $this->getWidth() * $scale/100;
      $height = $this->getheight() * $scale/100; 
      $this->resize($width,$height);
   }
   function resize($width,$height) {
      $new_image = imagecreatetruecolor($width, $height);
      imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
      $this->image = $new_image;   
   }      
}
?>
My code for the resizing where the script dies. It works well for photos but with higher resolution (2560x1440) it fails??:

Code: Select all

				include('incl/SimpleImage.php');
   				$image = new SimpleImage();
				$image->load('images/avatars/'.$name);
				

  				//This makes a 400 wide avatar
   				$image->resizeToWidth(400);
   				$image->save('images/avatars/'.strtolower($username.'_400.'.$ext));
   				
   				//This makes a 30x30 mini avatar	
   				$image->resize(30,30);
   				$image->save('images/avatars/'.strtolower($username.'_small.'.$ext));


Re: Image resizing SimpleImage.php, resolution problem?

Posted: Fri Apr 22, 2011 3:46 pm
by defroster
Found another thread with this problem. Could it be a RAM issue?
http://stackoverflow.com/questions/3319 ... size-limit

Re: Image resizing SimpleImage.php, resolution problem?

Posted: Sat Apr 23, 2011 6:15 am
by oscardog
Check the error logs on the server, it should have something in there if it was memory related. For a start I would increase the php_value upload_max_filesize & php_value memory_limit.

Also increase the max execution time on the script, but I doubt that's the problem.

Re: Image resizing SimpleImage.php, resolution problem?

Posted: Sat Apr 23, 2011 4:22 pm
by defroster
Thanks, I will try that!