1

I'm having a very problematic error with phpthumb: http://phpthumb.gxdlabs.com/ So basically, I have a form which uploads a profile picture. The uploading seems to work because it uploads the image in the directory. The problem is that it doesn't generate the thumbnails but I'm sure that all the variables and names are correct. It gives me the following error. Specifically 'Image file not found':

Fatal error: Uncaught exception 'Exception' with message 'Image file not found: ����' in {PATH}\phpthumb\ThumbBase.inc.php:193 Stack trace: #0 {PATH}\phpthumb\ThumbBase.inc.php(172): ThumbBase->triggerError('Image file not ...') #1 {PATH}\phpthumb\ThumbBase.inc.php(110): ThumbBase->fileExistsAndReadable() #2 {PATH}\phpthumb\GdThumb.inc.php(96): ThumbBase->__construct('??????JFIF?????...', false) #3 G:\EasyPHP\www\YourSlab\phpthumb\ThumbLib.inc.php(127): GdThumb->__construct('??????JFIF?????...', Array, false) #4 {PATH}\edit_profile.php(74): PhpThumbFactory::create('??????JFIF?????...') #5 {PATH}\edit_profile.php(80): generateThumbnail->createthumbnail(25) #6 {PATH}\edit_profile.php(118): set_profile_info('Mico Abrina', '1', 'asdf', 'asdf', '', 'asdf', 'asdf', '', '05', '4', '1996', 'G:\EasyPHP\tmp\...') #7 {main} thrown in {PATH}\phpthumb\ThumbBase.inc.php on line 193

I think its because I'm generating the thumbnails right after uploading it. How do I make it work?

<?php
    //upload images
    if (file_exists($profile_pic)) {
        $src_size = getimagesize($profile_pic); 

        if ($src_size['mime'] === 'image/jpeg'){
            $src_img = imagecreatefromjpeg($profile_pic);   
        } else if ($src_size['mime'] === 'image/png') {
            $src_img = imagecreatefrompng($profile_pic);
        } else if ($src_size['mime'] === 'image/gif') {
            $src_img = imagecreatefromgif($profile_pic);    
        } else {
            $src_img = false;   
        }

        if ($src_img !== false) {
            $md5sessionid = md5($_SESSION['user_id'].'asdf');
            imagejpeg($src_img, "profile_pic/$md5sessionid.jpg");
            //end of uploading images

            //image thumbnail creation class
            class generateThumbnail {
                public function createthumbnail($size) {
                $md5sessionidsecret = md5($_SESSION['user_id'].'asdf');
                $md5sessionidthumb = md5($md5sessionidsecret.''.$size);
                $path_to_thumb_pic = 'profile_pic/'.$md5sessionidthumb.'.jpg';
                $profile_pic = file_get_contents('profile_pic/'.$md5sessionidsecret.'.jpg');
                $thumb_profile_pic = PhpThumbFactory::create($profile_pic);
                $thumb_profile_pic->adaptiveResize($size, $size);
                $thumb_profile_pic->save($path_to_thumb_pic);
                }
            }
            //make the thumbnails
            $createThumbnail = new generateThumbnail();
            $createThumbnail->createthumbnail(25);
            $createThumbnail->createthumbnail(75);
            $createThumbnail->createthumbnail(175);
        }
    }
?>
Mico Abrina
  • 507
  • 1
  • 7
  • 25

1 Answers1

1

It appears that PhpThumbFactory::create() takes a file path as its first argument, unless you specify true for the third isDataStream argument. That is why you are getting the strange output in the exception where it says Image File Not Found.

You could do a few things to fix it:

// Either skip the file_get_contents call and pass the file path directly
$thumb_profile_pic = PhpThumbFactory::create('profile_pic/'.$md5sessionidsecret.'.jpg');

// or set the 3rd parameter isDataStream to true
$profile_pic = file_get_contents('profile_pic/'.$md5sessionidsecret.'.jpg');
$thumb_profile_pic = PhpThumbFactory::create($profile_pic, array(), true);
drew010
  • 68,777
  • 11
  • 134
  • 162
  • 1
    It seems that you cannot pass variables. This command made it work. $thumb_profile_pic = PhpThumbFactory::create('profile_pic/'.$md5sessionidsecret.'.jpg'); – Mico Abrina Feb 19 '12 at 08:47
  • Yeah I wasn't sure either. I looked at the code and it appears that they wanted to implement the data stream as it was mentioned in several places, but looking at the code I didn't think it would actually work but I didn't know if I was looking at an old version either. Glad it worked. – drew010 Feb 19 '12 at 08:50