Part of the image is missing after resize

See all posts Reply

Part of the image is missing after resize new!
by Mike, 12 years, 10 months ago
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


Appreciate any help! Thank you!Reply
Re: Part of the image is missing after resize new!
by colin, 12 years, 10 months ago
I am not sure what is happening. Is it reproducible? Does it do that with all images? Does it do it on different servers?Reply
Re: Part of the image is missing after resize new!
by Mike, 12 years, 9 months ago
Sorry for the delay.

No, not every image. Some make it through just fine, some images have 50% of the image missing, other have 80%.
I'm not really sure what the pattern is.

I'll try testing it on another server and see what happens.Reply
Re: Part of the image is missing after resize new!
by Mike, 12 years, 9 months ago
Tested this on another Ubuntu server running PHP 5.3.5.
The original server is running PHP 5.3.2.

Picking random images from the internet, some work and some don't. Weird...Reply
Re: Part of the image is missing after resize new!
by Mike, 12 years, 9 months ago
Just did a lot of troubleshooting on this and found that my issue had to do with how i was storing the file in MySQL. I was using BLOB instead of LONGBLOB, so my images were being cut off.

No issues with the Upload.class at all! Whew :)Reply