LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-09-2002, 05:25 PM   #1
GabeF
Member
 
Registered: Mar 2002
Location: New Hampshire, US
Distribution: Mandrake 8.0, Redhat 8.0
Posts: 101

Rep: Reputation: 15
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");
Returns the error,
"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?
 
Old 12-10-2002, 11:31 AM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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" ));
 
Old 12-10-2002, 01:33 PM   #3
GabeF
Member
 
Registered: Mar 2002
Location: New Hampshire, US
Distribution: Mandrake 8.0, Redhat 8.0
Posts: 101

Original Poster
Rep: Reputation: 15
Thanks for the response. I'll try both of your suggestions.
 
Old 12-10-2002, 07:01 PM   #4
GabeF
Member
 
Registered: Mar 2002
Location: New Hampshire, US
Distribution: Mandrake 8.0, Redhat 8.0
Posts: 101

Original Poster
Rep: Reputation: 15
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?
 
Old 12-11-2002, 03:34 PM   #5
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
You either need to set the content type to image instead of html or write the html code to display the image.
 
Old 12-11-2002, 04:22 PM   #6
GabeF
Member
 
Registered: Mar 2002
Location: New Hampshire, US
Distribution: Mandrake 8.0, Redhat 8.0
Posts: 101

Original Poster
Rep: Reputation: 15
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.
 
Old 12-12-2002, 10:56 AM   #7
lhoff
Member
 
Registered: Jun 2001
Location: Chicago
Distribution: Mandrake 10.0 Official
Posts: 181

Rep: Reputation: 30
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!
 
Old 12-12-2002, 12:54 PM   #8
GabeF
Member
 
Registered: Mar 2002
Location: New Hampshire, US
Distribution: Mandrake 8.0, Redhat 8.0
Posts: 101

Original Poster
Rep: Reputation: 15
Thank you again for your help! Yes there was another script; actually it was just an include() statement.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk: fatal:cannot open file for reading (no such file or Directory) in Linux sangati vishwanath Linux - Software 4 07-06-2005 12:59 AM
libawt.so: libXp.so.6: cannot open shared object file: No such file or directory man26 *BSD 0 09-10-2004 08:34 AM
How to open a wps file in open office 1.1 oneiric Linux - Software 4 04-15-2004 04:07 AM
How to open or make a .php file in emacs?? eye Linux - Software 1 12-02-2003 12:19 AM
imagecreatefromjpeg problem niehls Programming 2 10-31-2003 05:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration