PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
TonsOfFun
Forum Commoner
Posts: 54 Joined: Wed Jun 02, 2010 7:37 pm
Post
by TonsOfFun » Mon Jan 10, 2011 5:25 pm
I am trying to create a script that will crop an image to 200x200 but I keep getting the error:
The image “[location/to/page]” cannot be displayed because it contains errors.
Here's my code:
Code: Select all
$orig = 'photos/1c23e596271d8eabb2e58d65c79b4beb.jpg';
list($width,$height) = getimagesize($orig);
$imageResized = imagecreatetruecolor(200, 200);
$imageTmp = imagecreatefromjpeg ($orig);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, 200, 200, $width, $height);
imagejpeg($imageResized,100);
Thanks.
McInfo
DevNet Resident
Posts: 1532 Joined: Wed Apr 01, 2009 1:31 pm
Post
by McInfo » Mon Jan 10, 2011 5:45 pm
1. Are you sure the source image file exists?
2. An appropriate Content-Type header should be sent before sending image data.
Code: Select all
header('Content-Type: image/jpeg');
3. Do you want to create a file named "100", or do you want 100% quality?
Code: Select all
imagejpeg($imageResized, null, 100); // ($image, $filename, $quality)
mikecampbell
Forum Commoner
Posts: 38 Joined: Tue Oct 12, 2010 7:26 pm
Post
by mikecampbell » Mon Jan 10, 2011 5:46 pm
I think you probably want to do this:
Code: Select all
imagejpeg($imageResized,null,100);
TonsOfFun
Forum Commoner
Posts: 54 Joined: Wed Jun 02, 2010 7:37 pm
Post
by TonsOfFun » Mon Jan 10, 2011 6:17 pm
McInfo wrote: 1. Are you sure the source image file exists?
2. An appropriate Content-Type header should be sent before sending image data.
Code: Select all
header('Content-Type: image/jpeg');
3. Do you want to create a file named "100", or do you want 100% quality?
Code: Select all
imagejpeg($imageResized, null, 100); // ($image, $filename, $quality)
Yes, it does exist.
I have the appropriate header. It's the first thing, right before the DOCTYPE declaration.
I changed it to
Code: Select all
imagejpeg($imageResized,null,100); and I'm getting the same error.
McInfo
DevNet Resident
Posts: 1532 Joined: Wed Apr 01, 2009 1:31 pm
Post
by McInfo » Mon Jan 10, 2011 7:39 pm
TonsOfFun wrote: right before the DOCTYPE declaration.
That could be the problem. Image files do not contain HTML. Image data and HTML are not sent in the same server response.
TonsOfFun
Forum Commoner
Posts: 54 Joined: Wed Jun 02, 2010 7:37 pm
Post
by TonsOfFun » Mon Jan 10, 2011 8:26 pm
Thanks McInfo, that solved it.