Link to home
Start Free TrialLog in
Avatar of pingeyeg
pingeyeg

asked on

Function imagecreatetruecolor not working

I know this function, which is built into PHP, was working before, but it appears it has died on me.  I'm now getting my error friendly message:

The image create true color did not work

I did some investigating on this, but nothing is really ringing any bells.  The source code I have is below.
function create_right_size_image($target_path, $width=430) {
 
        	$source = imagecreatefromjpeg($target_path);
 
        	$imageX = imagesx($source);
        	$imageY = imagesy($source);
 
        	$tnailX = $width;
        	$tnailY = (int) (($tnailX * $imageY) / $imageX );
 
        	$target = imagecreatetruecolor($tnailX, $tnailY)
     			or die("The image create true color did not work");
			//      $target = imagecreate($tnailX, $tnailY);
        	imagecopyresampled ($target, $source, 0, 0, 0, 0, $tnailX, $tnailY, $imageX, $imageY)
        		or die("The image copy resampled did not work");
			//      imagecopyresized   ($target, $source, 0, 0, 0, 0, $tnailX, $tnailY, $imageX, $imageY);
 
			$ok = imagejpeg ($target, $target_path, 100);
			return true;
	}

Open in new window

SOLUTION
Avatar of dsmile
dsmile
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pingeyeg
pingeyeg

ASKER

I'm not getting any error messages when I add those two functions above except for what I already commented on above.

Also, my GD version is bundled (2.0.34 compatible).

The $target_path is equal to ../images/items/IMG_0019.JPG, which means it does exist.
Run this and check your GD version

phpinfo();

Then please check the spelling you used in the ini_set() function.
http://www.php.net/manual/en/ini.list.php

You might also want to post the complete script that is failing, thanks.
I guess you may not've read my comment above, but my GD version is:

2.0.34 compatible

This is what I'm using for the ini_set() function:

ini_set('display_error', 'On');
I read your comment.  I simply want you to verify your GD version by looking at phpinfo() right now, and not from an alternative source.  

Then please check the spelling you used in the ini_set() function.
http://www.php.net/manual/en/ini.list.php

I believe that you want this:
ini_set('display_errors', 'On');

You might also want to post the complete script that is failing, thanks.
You can check the GD version here:

http://www.prettypersuasions.net/phpinfo.php

Wow, yeah, I missed the 's' in display_errors.  These are my errors:

../images/items/IMG_0019.JPG
Warning: copy(../images/items/IMG_0019.JPG) [function.copy]: failed to open stream: Permission denied in /admin/addproduct.php on line 34

Warning: imagecreatefromjpeg(../images/items/IMG_0019.JPG) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /admin/includes/functions.php on line 6

Warning: imagesx(): supplied argument is not a valid Image resource in /admin/includes/functions.php on line 8

Warning: imagesy(): supplied argument is not a valid Image resource in /admin/includes/functions.php on line 9

Warning: Division by zero in /admin/includes/functions.php on line 12

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /admin/includes/functions.php on line 14
The image create true color did not work
So it looks like the attempt to put the image file into ../images/items/IMG_0019.JPG failed because of directory permissions, and the rest of the messages fell like dominoes.
Unusual because I just used FireFTP to change the directoy permissions to allow execution of all files under the Admin directory.
I think you might want the equivalent of CHMOD to 0755.  It allows read as well as everything else you might need.
Ok, so looks like the permission issue has been resolved, but now it's telling me the file doesn't exist, even though I'm grabbing it from my hard drive.
Do you think it has anything to do with the copy function I'm using?

copy($_FILES['image']['tmp_name'], $target_path);

Is that an outdated way of copying the file to the server?
This is very odd.  Before I came to you guys, the path to where the file was to be is:

../images/items/

That's when the issues were occurring.  I removed the ../ and just left it with /, tried it and still got the errors you saw above.  I then put the relative URL the way it was before and the issue went away.  That tells me the issue is only temporarily fixed.  Got any ideas?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial