G--D--- GD and PHP!
March 1, 2007 7:15 AM   Subscribe

Help me with PHP configuration for GD and JPEG. I can't determine why JPEG functions aren't working.

I've installed PHP 5.2.0 on a FreeBSD server with the following:

'./configure' '--with-mysql' '--with-apxs=/usr/local/apache/bin/apxs' '--with-gd' '--with-gettext=/usr/local/lib' '--with-png-dir=/usr/local/lib' '--with-jpeg-dir=/usr/local/lib' '--with-freetype-dir=/usr/local/lib' '--with-zlib-dir=/usr/local/zlib-1.2.3'


When I check the GD section on phpinfo(), here is what I see:

GD Support enabled
GD Version bundled (2.0.28 compatible)
GIF Read Support enabled
GIF Create Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled

And of course, a script that I'm using with the ImageCreateFromJPEG function fails. What I am missing? Before you ask, libjpeg.so exists in /usr/local/lib
posted by Robert Angelo to Computers & Internet (13 answers total) 1 user marked this as a favorite
 
a script that I'm using with the ImageCreateFromJPEG function fails

Define "fails." The function name isn't capitalized; it's a lowercase imagecreatefromjpeg(). So if you're using a capitalized name and getting a "function does not exist" error, that's probably your problem. But if you're using the lowercase name, what exact error are you getting?
posted by scottreynen at 8:05 AM on March 1, 2007


Response by poster: Scott, it's not case sensitive. The function works either way on another FreeBSD LAMP installation.

On this installation, when I change it to lower case, I get this error:
Fatal error: Call to undefined function imagecreatefromjpeg()

The problem is that JPEG is not supported by GD here -- see the phpinfo() excerpt above.
posted by Robert Angelo at 8:37 AM on March 1, 2007


Response by poster: OK, not Lamp -- what do I call it, BAMP?
posted by Robert Angelo at 8:37 AM on March 1, 2007


From the page scottreynen linked to: Does this help?

As for case: You have to capitalize by PHP's rules, not gd's rules.
posted by ardgedee at 8:42 AM on March 1, 2007


No to be insulting, but did you make sure to do a make clean, install AND apachectl restart?
posted by phearlez at 8:44 AM on March 1, 2007


Best answer: I don't know if either of these items will help, but problems with this function are apparently pretty common.

This comment on the php.net page for imagecreatefromjpeg() suggest that jpeg header information can cause this function to fail, and also suggests an application to strip out the header info.

Also, there's an unrelated problem/solution identified on this blog.
posted by treepour at 9:49 AM on March 1, 2007


Response by poster: From that link:
If phpinfo() shows GD, but not JPEG support, then that's the problem. You would think that --with-gd would do the right thing since it does check for the existance of libjpeg (and finds it) and add that feature to GD, but it doesn't in v4.4.4 at least on RHEL v2.1, RHEL v3, CentOS v2.1 or CentOS v4.3.

On those platforms, it's *important* that --with-jpeg-dir be *before* --with-gd. If it's not, GD won't build with jpeg support as if --with-jpeg-dir had never been specified...


I'll try redoing the configure, though it will have to wait until this evening. :-(

No offense taken, phearlez. :-) Yup, I did all that, too. I've been stumped. That's why I asked for help.
posted by Robert Angelo at 9:50 AM on March 1, 2007


Response by poster: treepour, that blog link describes exactly the sort of problem-solving I've been trying to do -- nice to know I'm know alone. :-) I may well need to fuss with the configure command some more, also test that my /usr/local/lib/libjpeg.so is not corrupt somehow.
posted by Robert Angelo at 9:54 AM on March 1, 2007


Are you compiling from raw source, or using ports?

If you aren't using ports, why not?
posted by tomierna at 10:22 AM on March 1, 2007


Scott, it's not case sensitive.

Huh. I've been developing in PHP for several years and I always thought PHP functions were case-sensitive, but you're right; they aren't. Thanks. I hope this AskMe turns out as helpful for you as it did for me.
posted by scottreynen at 4:53 PM on March 1, 2007


Response by poster: tomierna: I'm compiling from source (see the question), not using ports. Why? I'm just old-fashioned. On any system I'm responsible for, I want to have complete control of what I'm doing, how I install whatever I install, where it's located, etc, etc. It does produce some headaches (like this one) but also provides maximum flexibility for cases where there isn't a port combo that meets my desires.
posted by Robert Angelo at 6:42 PM on March 1, 2007


Response by poster: treepour, the info from that link was spot on. I recompiled PHP doing "--with-gd" at the end of the "./configure" command, and now it shows up in phpinfo with JPEG support enabled. Haven't tested this yet -- tired and going to bed! -- but I'm sure it will work now.
posted by Robert Angelo at 9:59 PM on March 1, 2007


Glad to hear it seems to be working out, thanks for letting us know. I'll keep that bookmark handy!
posted by treepour at 5:01 PM on March 2, 2007


« Older Juggling a job and freelance work   |   Where to find a nice eBay/auction design template? Newer »
This thread is closed to new comments.