class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
I have a simple function for resizing images. After I resize the image, part of the image is always missing. I'm pretty sure the resize worked fine when I first started playing with the upload class, but after embedding it in to my PHP code, the images aren't displaying properly anymore.
Here's my resizeImage function:
public function resizeImage($width, $height, $filepath) {
$config = Config::getInstance();
$handle = new upload($filepath);
$handle->image_resize = true;
$handle->image_x = $width;
$handle->image_y = $height;
$handle->process($config->getValue('uploadedfile_dir'));
if (!$handle->processed) {
echo "Error: " . $handle->error;
print_r($handle->log);
}
$filepath = $handle->file_dst_pathname;
$handle->clean();
return $filepath;
}
Original image: http://tinypic.com/r/28m0osn/7 Resized image: http://tinypic.com/view.php?pic=2nrmzjn&s=7
Log: system information - class version : 0.30 - operating system : Linux - PHP version : 5.3.2-1ubuntu4.7ppa5~lucid1 - GD version : 2.0 - supported image types : png jpg gif bmp - open_basedir : no restriction - upload_max_filesize : 2M (2097152 bytes) - language : en_GB source is a local file /home/ubuntu/uploads/Nature.jpg - local file name OK determining MIME type - Checking MIME type with Fileinfo PECL extension MAGIC path defaults to /usr/share/file/magic MIME type detected as image/jpeg; charset=binary by Fileinfo PECL extension - MIME validated as image/jpeg source variables - You can use all these before calling process() file_src_name : Nature.jpg file_src_name_body : Nature file_src_name_ext : jpg file_src_pathname : /home/ubuntu/uploads/Nature.jpg file_src_mime : image/jpeg file_src_size : 65535 (max= 2097152) file_src_error : 0 - source file is an image image_src_x : 422 image_src_y : 274 image_src_pixels : 115628 image_src_type : jpg image_src_bits : 8 process file to /home/ubuntu/uploads/ - file size OK - file mime OK : image/jpeg - file name safe format - destination variables file_dst_path : /home/ubuntu/uploads/ file_dst_name_body : Nature file_dst_name_ext : jpg - image operation, keep extension - checking for auto_rename auto_rename to Nature_2.jpg - destination file details file_dst_name : Nature_2.jpg file_dst_pathname : /home/ubuntu/uploads/Nature_2.jpg - Nature_2.jpg doesn't exist already - image resizing or conversion wanted - source image is JPEG - setting destination file type to jpg - resizing... use plain sizes resized image object created image_src_x y : 422 x 274 image_dst_x y : 138 x 89 - converting... fills in transparency with default color - saving image... JPEG image created image objects destroyed - process OK /var/www/image_previews/782.jpg
I'm pretty sure the resize worked fine when I first started playing with the upload class, but after embedding it in to my PHP code, the images aren't displaying properly anymore.
Here's my resizeImage function:
Original image: http://tinypic.com/r/28m0osn/7
Resized image: http://tinypic.com/view.php?pic=2nrmzjn&s=7
Log:
system information
- class version : 0.30
- operating system : Linux
- PHP version : 5.3.2-1ubuntu4.7ppa5~lucid1
- GD version : 2.0
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- upload_max_filesize : 2M (2097152 bytes)
- language : en_GB
source is a local file /home/ubuntu/uploads/Nature.jpg
- local file name OK
determining MIME type
- Checking MIME type with Fileinfo PECL extension
MAGIC path defaults to /usr/share/file/magic
MIME type detected as image/jpeg; charset=binary by Fileinfo PECL extension
- MIME validated as image/jpeg
source variables
- You can use all these before calling process()
file_src_name : Nature.jpg
file_src_name_body : Nature
file_src_name_ext : jpg
file_src_pathname : /home/ubuntu/uploads/Nature.jpg
file_src_mime : image/jpeg
file_src_size : 65535 (max= 2097152)
file_src_error : 0
- source file is an image
image_src_x : 422
image_src_y : 274
image_src_pixels : 115628
image_src_type : jpg
image_src_bits : 8
process file to /home/ubuntu/uploads/
- file size OK
- file mime OK : image/jpeg
- file name safe format
- destination variables
file_dst_path : /home/ubuntu/uploads/
file_dst_name_body : Nature
file_dst_name_ext : jpg
- image operation, keep extension
- checking for auto_rename
auto_rename to Nature_2.jpg
- destination file details
file_dst_name : Nature_2.jpg
file_dst_pathname : /home/ubuntu/uploads/Nature_2.jpg
- Nature_2.jpg doesn't exist already
- image resizing or conversion wanted
- source image is JPEG
- setting destination file type to jpg
- resizing...
use plain sizes
resized image object created
image_src_x y : 422 x 274
image_dst_x y : 138 x 89
- converting...
fills in transparency with default color
- saving image...
JPEG image created
image objects destroyed
- process OK
/var/www/image_previews/782.jpg
Appreciate any help! Thank you!