defroster Posted April 22, 2011 Share Posted April 22, 2011 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 <?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??: 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)); Quote Link to comment https://forums.phpfreaks.com/topic/234466-image-resizing-simpleimagephp-fine-with-low-res-problem-with-high-res/ Share on other sites More sharing options...
defroster Posted April 22, 2011 Author Share Posted April 22, 2011 Found another thread with this problem. Could it be a RAM issue? http://stackoverflow.com/questions/3319603/php-image-resizing-not-working-is-there-a-file-size-limit Quote Link to comment https://forums.phpfreaks.com/topic/234466-image-resizing-simpleimagephp-fine-with-low-res-problem-with-high-res/#findComment-1205030 Share on other sites More sharing options...
PFMaBiSmAd Posted April 22, 2011 Share Posted April 22, 2011 To resize an image or do any other image manipulation, you must make an uncompressed bitmap version of that image. jpeg, gif, png are compressed image formats, where sections of the image are sampled to get the colors used in that section and then each section is compressed, taking into account just the range of colors used in that section instead of all the possible colors. An 2560x1440 image could easily take 20-50MB of memory. If you turn on full php error reporting (error_reporting = E_ALL and display_errors = ON) and comment out any header() statements in your code, php will likely output an error that would tell you why the code is failing. Quote Link to comment https://forums.phpfreaks.com/topic/234466-image-resizing-simpleimagephp-fine-with-low-res-problem-with-high-res/#findComment-1205034 Share on other sites More sharing options...
defroster Posted April 22, 2011 Author Share Posted April 22, 2011 Thanks I will see if I can produce any fine errors Quote Link to comment https://forums.phpfreaks.com/topic/234466-image-resizing-simpleimagephp-fine-with-low-res-problem-with-high-res/#findComment-1205038 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.