Guest Posted July 29, 2008 Share Posted July 29, 2008 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?! Link to comment https://forums.phpfreaks.com/topic/117180-solved-imagejpeg-donest-display-anything/ Share on other sites More sharing options...
obsidian Posted July 29, 2008 Share Posted July 29, 2008 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. Link to comment https://forums.phpfreaks.com/topic/117180-solved-imagejpeg-donest-display-anything/#findComment-602731 Share on other sites More sharing options...
Guest Posted July 29, 2008 Share Posted July 29, 2008 When I try to run the function ini_set('memory_limit', '60M'), it doesn't seem to have any effect on my php.ini. Even when I edit php.ini directly and then use phpinfo(), it still says memory_limit is set to 16M. How do I change this? Link to comment https://forums.phpfreaks.com/topic/117180-solved-imagejpeg-donest-display-anything/#findComment-602774 Share on other sites More sharing options...
obsidian Posted July 29, 2008 Share Posted July 29, 2008 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? Link to comment https://forums.phpfreaks.com/topic/117180-solved-imagejpeg-donest-display-anything/#findComment-602779 Share on other sites More sharing options...
dubc07 Posted July 29, 2008 Share Posted July 29, 2008 Sometimes just depending on your hosting, The php.ini changes will not be immediate. or the Hosting company has a set of ini rules that doesn't allow memory expansion. Call you hosting provider. to see if they allow ini changes. Link to comment https://forums.phpfreaks.com/topic/117180-solved-imagejpeg-donest-display-anything/#findComment-602782 Share on other sites More sharing options...
Guest Posted July 29, 2008 Share Posted July 29, 2008 I am on a localhost. I tried restarting Apache, rebooting PC, emptying cache to no effect. Link to comment https://forums.phpfreaks.com/topic/117180-solved-imagejpeg-donest-display-anything/#findComment-602793 Share on other sites More sharing options...
Guest Posted July 29, 2008 Share Posted July 29, 2008 XAMPP apparently has three php.ini files. The one I needed to edit was in the apache/bin directory. It looks like most servers have memory_limit set to around 32MB, but mine was on 16MB. Thanks for your help Link to comment https://forums.phpfreaks.com/topic/117180-solved-imagejpeg-donest-display-anything/#findComment-603052 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.