php imagecreatefromjpeg can't open file
I have been searching the net for a solution to this problem for a couple hours, and I can't find any solution...I am writing a script which will resize an image from 640x480 to 320x240 to display on a page. I am using PHP4.x.x with GD2.0. The followng line:
Code:
$image = imagecreatefromjpeg("/path/to/image.jpg"); "Warning: imagecreatefromjpeg: Unable to open '/images/uploaded/rail_small.JPG' for reading in /usr/local/apache/htdocs/image_test.php on line 3 " I tried several different images all with the same result. I know that the permissions are set right and the path is right. Is this the result of an error I made in configuration? |
As a test you can try another directory like /tmp.
I've had much better luck resizing images with mogrify than with the GD libs. The images come out looking much better. I use a php command like this: Code:
exec(EscapeShellCmd( "/usr/X11R6/bin/mogrify -geometry " . $newwidth . "x" . $newheigth . "! $thumbfilename" )); |
Thanks for the response. I'll try both of your suggestions.
|
Alright. I tried your exec() solution, but couldn't figure out how to get it working. I fiddled with the imagecreatefromjpeg function some more and it is working now (although I don't really know what I did). Now my problem is that I want to display a resized picture on a web page randomly. I need to set the Content-type to image/jpeg, but I can't because it has already been set to text/html. Is there a way around this?
|
You either need to set the content type to image instead of html or write the html code to display the image.
|
I tried setting the Content-type, but it was already set to text/html and I can't change it. The images I am using are to stay full size and only be resized to display on this page. For this reason, they are not saved as a small image and so can't use an img tag.
|
I'm assuming the reason your Content-type got set to "text/html" is that another script has already begun HTML output. Yes?
Try putting your GD scripts into another script file (or an object). Here's an example of using another script file: /*(jpegscript.php has all the GD image processing scripts and returns the Content-type at the end of its routine.)*/ Set the tag in the HTML: <img src="jpegscript.php?sourceimg=originalImage.jpg"> This will return the correct Content-type for an image where it is needed -- in the img tag. Good luck! |
Thank you again for your help! Yes there was another script; actually it was just an include() statement.
|
All times are GMT -5. The time now is 04:29 PM. |