Jump to content

[SOLVED] imagejpeg dones't display anything


Guest

Recommended Posts

I have a script that stores images to a mysql table and outputs them with the file image.php, which looks like this:

 

<?php
include('../dbconnect.php');
$imageName = $_GET['name'];
$imageQuery = "SELECT pic FROM images WHERE name = '$imageName'";
$imageResult = mysql_query($imageQuery) or die("Error in query: $imageQuery. ".mysql_error().".");
mysql_close($connection);
header('Content-type: image/jpeg');
$image = imagecreatefromstring(mysql_result($imageResult, 0));
$oldWidth = imagesx($image);
$oldHeight = imagesy($image);
if ($_GET['width'] == 0) {
  $newWidth = $oldWidth;
} else {
  $newWidth = $_GET['width'];
}
if ($_GET['height'] == 0) {
  $newHeight = $oldHeight;
} else {
  $newHeight = $_GET['height'];
}
$newImage = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $oldWidth, $oldHeight);
imagejpeg($newImage, null, 100);
?>

 

It works totally fine for most images, but it has problems with large images. For instance, I have an image that is 1200px x 1600px. When I try to load it without width and height parameters, it just shows the filename: http://localhost/cmsnap/image.php?name=test.jpg. However, if I include width and height parameters under a certain amount, it will resize and resample the image and output it.

 

i.e., this works: http://localhost/cmsnap/image.php?name=test.jpg&width=1200&height=1159

but this doesn't: http://localhost/cmsnap/image.php?name=test.jpg&width=1200&height=1160

Also, this works: http://localhost/cmsnap/image.php?name=test.jpg&width=872&height=1600

but this doesn't: http://localhost/cmsnap/image.php?name=test.jpg&width=873&height=1600

 

Am I overloading this function or something? Is there some kind of a limit to the file size? How do I fix this?!

It's very possible that your script memory limit or execution time is being exceeded. Check your php.ini file to see what your memory_limit. Working with images is pretty intensive, and it doesn't take much to grow beyond the bounds when you're manipulating larger images. If this is indeed the case, you can just do ini_set('memory_limit', '60M'); or whatever you think your script will need to run. Granted, this is only one possible solution, so keep us posted on what errors you may be getting.

If your host has PHP safe mode turned on, you won't be able to. It's not as common on major hosts to find it on, but it is occasionally. If you look at your phpinfo() output and search for safe mode, what is the setting for that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.