Image styles aren't working on an Ubuntu 9.10 install, even though there is no complaint from hook_requirements.

I know that the conflict over the PHP gd library has been there in Ubuntu installs for some time, and I know about the workarounds. The issue here is that Drupal under Ubuntu 9.10 does not complain, it just fails to work.

What I did:

  • Standard Ubuntu 9.10 64-bit install. php5-gd 5.2.10.dfsg.1-2ubuntu6.3
  • Drupal 7 current HEAD install
  • admin/reports/status reports: GD library 2.0 or higher, in green, no errors
  • Navigate to admin/config/media/image-styles/edit/large
  • Add the "Desaturate" effect

What I expected: The preview would be desaturated.

What happened: Nothing. Both previews are full color. It appears that GD is not working.

Additional Information:

  • I checked a Drupal 6 install. It reports the expected The installed version of PHP GD does not support image filtering
  • I checked an Ubuntu 10.04 install. Everything works there. (But I assume that's because Ubuntu has finally got a stock php-gd that works
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rfay’s picture

I forgot to mention that I'll be happy to launch and make available an Ubuntu 9.10 instance if somebody needs it to work on this. I also have a complete Virtualbox image which you could use.

eojthebrave’s picture

This is what I think is going on. You've got GD installed, though it is not the version bundled with PHP. As a result some of the image effects will work (scale for example), and some will not. Desaturate and rotate. Do you get watchdog messages to the tune of "The image %file could not be desaturated because the imagefilter() ..."?

If so, you've got a partially functioning version of GD.

I think we should adjust the _requirements hook to test for existence of imagefilter() and imagerotate() and if they are missing return a warning. Image styles will still function without them, and we're already checking if the function exists before trying to use it. We just need to make it more obvious to the user that they're missing some functionality.

We might want to consider hiding the desaturate and rotate effects for system that do not support them as well. Not sure if that would get in for D7 or not though.

rfay’s picture

I do get an error in the log:

Image desaturate failed using the gd toolkit on modules/image/sample.png (image/png, 480x480)

An interesting factoid about this problem: The standard Ubuntu fix, switching to the dotdeb libraries, doesn't work for 9.10, as there's a dependency problem.

rfay’s picture

Status: Active » Needs review
FileSize
1.16 KB

Here's a first cut at the suggestion in #2 in color.module's hook_requirements(). It shows the problem in admin/reports/status on my nonfunctioning install, and shows OK on a functioning install.

It just checks for the existence of imagefilter() and imagerotate() in addition to the traditional check, and emits a (slightly altered) error message.

eojthebrave’s picture

Status: Needs review » Needs work

I think the new checks should go in image.install instead of color.install.

1. Color module doesn't make use of either imagefilter() or imagerotate().
2. Its possible to have color disabled and image enabled which would lead to inaccurate status reports and people getting confused when desaturate doesn't work.

I would also like to see the warning be a little more explicit about what exactly is missing. This is important because it gives people a little head start when they are trying to figure out what is wrong with their GD. Perhaps something along the lines of:

The GD Library for PHP is enabled, but was compiled without support for functions used by the rotate and desaturate effects. It was probably compiled using the official GD libraries from http://www.libgd.org instead of the GD library bundled with PHP. You should recompile PHP --with-gd using the bundled GD library. See: http://www.php.net/manual/book.image.php

That link in color.module to the PHP docs should change to, it points to the function reference page, not very useful for people who are trying to debug installation/configuration problems. That's for another issue though.

Thanks for the patch.

rfay’s picture

I was surprised to find the hook_requirements() in color module instead of image module.

Should we have the GD check in both places? In different forms?

Neither depends on the other.

rfay’s picture

Status: Needs work » Needs review
FileSize
27.03 KB
1.83 KB

OK, here's an implementation of image_requirements().

The bad thing is that basically two separate modules are implementing the need for gd. That means that if GD isn't there, there will be two separate warnings about it. And if GD is there (but broken, as in my case) then one requirement will say it's OK, the other not.

BTW: In my case, color_requirements() is actually correct in its report on Ubuntu 9.10: Color module works fine.

I don't think that two modules can both add input in hook_requirements, so know of no way to consolidate this information.
GD_warning.png

dman’s picture

The bad thing is that basically two separate modules are implementing the need for gd. That means that if GD isn't there, there will be two separate warnings about it. And if GD is there (but broken, as in my case) then one requirement will say it's OK, the other not.

True, but accurate. As we would rather have more clues than less, and the requirements are from two different modules - and technically are requiring different functionality, then I'd vote for the two slightly different warnings. Your fix is fine, I think.

eojthebrave’s picture

I'm okay with keeping the requirements checks separate. Otherwise, we could put them in system_requirements(). Which, is already checking for the existence of the GD PHP extension. And since the GD toolkit we're using for image manipulation is provided by system.module I think this would be an okay place as well.

Picky, but can we change the link in the second requirements error to http://www.php.net/manual/book.image.php as per #5. Again, I just think it is a more useful place to send the user when trying to resolve this issue.

eojthebrave’s picture

rfay’s picture

So we need to decide if a consolidated hook_requirements should go into system_requirements(). The only problem with that is that GD is *not* a requirement if color.module or image.module is not in use.

Is this RTBC if we're *not* going to do that?

eojthebrave’s picture

Status: Needs review » Needs work

I'm okay with this method, but would still like to see the link changed as per #9.

If we're going this route I would also like to change the title of the color.module requirement to something like 'GD Library PNG Support'. This makes it clear that the requirement in this instance is for a specific GD functionality and not just GD in general.

If you want to re-roll your patch I would be happy to summarize the issue and RTBC.

rfay’s picture

Title: gd not functional on Ubuntu 9.10 even though hook_requirements doesn't report a problem » Improve GD library hook_requirements() for color and image modules
Status: Needs work » Needs review
FileSize
29.47 KB
3.98 KB

OK, I went ahead and changed both modules' hook_requirements(). These are quite minor changes.

The purpose of this patch is to explain clearly to administrators what is working or not working in the GD library, whether it's needed by image or color module. It now:

  • Adds hook_requirements() to image.install so that it reports when GD support is inadequate, as is the case on stock Ubuntu 9.10.
  • Changes color.install's hook_requirements() to explain more clearly that it's whining about PNG support when it whines. Also changed the requirements key to 'color_gd' to match the 'image_gd' used in image.install.
  • Changed the link in both places to a more useful PHP link per #9.

GD_info.png

eojthebrave’s picture

Status: Needs review » Reviewed & tested by the community

Yeah! Thanks rfay.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

jbrown’s picture

FileSize
1.02 KB

This should just be a warning - I'm sure a lot of people wont need rotate or desaturate, but don't want a permanent error at the top of the configuration page.

rfay’s picture

Status: Fixed » Needs review
eojthebrave’s picture

Status: Needs review » Reviewed & tested by the community

I'm okay with this just being a warning. Both of the image api functions that use the GD functions in question check for their existence before using them and log errors via watchdog. So we're not likely to get any WSOD or Fatal errors.

I still think we should consider hiding the rotate/desaturate effects if they don't work. But that can be discussed here #747042: Rotate effect

rfay’s picture

Status: Reviewed & tested by the community » Needs work

I'm OK with a warning too... But can we do it on both of them? The warning about not having enough GD memory and such is always a waste... and it's even less critical than the image.module stuff.

redneck27’s picture

I have the same issue.
I can't even publish pictures anymore.
When i upload them, i see them for a short time. When i refresh my page the images are gone.

Does anyone know what may cause this?

Thanks in advance

mgifford’s picture

Can someone please summarize a resolution this for major distros.

I'm thinking an
# apt-get install php5-gd

or something like that is inline here.

If it's not part of the major Linux distros then really it's rather annoying that Drupal's asking us to build an app for scratch not to get a nasty red error message on the status page.

dman’s picture

RE documenting:
It may not always be turned on automatically in hand-compiled raw distros, but it is usually enabled as a matter of course by hosting providers. And is in most domestic/developer precompiled default binary installs of PHP, and XAMPP and MAMPP. (but not OSX)

Folk who have the authority to run apt-get are expected to have the knowledge to run apt-get.
So it's a documentation matter if the current recommendation "An image library for PHP such as the GD library is needed for image manipulation needs to have an extra line added "And to do that you run apt-get install php5-gd"
Some hand-holding is good, when the instruction is just a short copy-paste like that. I know I always forget, and try "apt-get install gd" unless I remember right. So it'll be handy to be documented there.

So ...

If you have administrator rights on a Debian/Ubuntu server, and GD is not already available (see your phpinfo) it can usually be installed by going:
sudo apt-get install php5-gd
See the ImageMagick install instructions for your platform if you want that.

has now been added to the (already huge) system requirements. The system requirements should not IMO turn into a HOWTO - which is better left to the install instructions themselves, but this small one is short.

mgifford’s picture

Ok, but sadly that's only as good as the repository you're working with. Doesn't seem to work with stable debian.

$ sudo apt-get install php5-gd
[sudo] password for me:
Reading package lists... Done
Building dependency tree
Reading state information... Done
php5-gd is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 7 not upgraded.

eojthebrave’s picture

I don't have a debian box to test this one but I'm not sure that the standard php5-gd will actually fix the problem. My understanding is that the issue stems from the fact that debian uses the "official" libgd package though as of 5.x PHP has it's own forked version of the GD library (built in, and with a number of changes that haven't been contributed upstream as of yet). Image Styles/Effects depends on some of the functions that exist in the PHP version of GD but not the libgd version. Debian doesn't build with bundled libraries as per their policies ... and thus chaos ensues.

In order to get a fully functioning version of PHP + GD working on Debian you need to re-compile php using the --with-gd flag, just using 'php5-gd' won't actually do you any good.

At least that's my understanding of the situation. @rfay may be able to confirm or shed some more light on this as he alerted me to the problem originally.

rfay’s picture

Spinning this off into #878778: GD package problems with Debian/Ubuntu: Document distro workarounds, probably the right place to do this.

@mgifford, your contribution in sorting this out is welcome. We probably need a page on Debian as well. #878778-1: GD package problems with Debian/Ubuntu: Document distro workarounds has a proposed debian 5 approach.

jlnd’s picture

I was having the original problem described. I found this ticket because I did a web search for "drupal GD library rotate and desaturate effects". I know this ticket is about changing the messages and warnings that are displayed, but in case anyone else is looking to solve this problem on their install... I followed the link in #25 (thanks @rfay) and eventually ended up on this page: http://drupal.org/node/540838 . I followed the directions and it works. (I'm running Ubuntu Server 8.04.)

mgifford’s picture

Seems like the Debian folks aren't going to be making it easy to install GD the way Drupal wants to. "php5-gd is already the newest version" and we're still getting the error "GD library rotate and desaturate effects" even though the phpinfo() reports that "GD Version 2.0 or higher".

According to the system requirements we should have the option of using ImageMagick too "ImageMagick is also supported for basic image manipulations in Drupal core", but sadly this doesn't get rid of this error.

Also according to the phpinfo() results "imagick module version 2.1.1-rc1" so this should give me the power to rotate images or do other stuff that core's worried about.

So either D7 needs to be updated to support imagemagick or (in a worse case senario) the docs need to be changed. Also it should be clear that other than recompiling PHP yourself, the only approach to do this is to use non-core sources.

Ubuntu 10.04 seems to take care of it out of the box, but not sure when the Debian community will.

mgifford’s picture

FileSize
1.51 KB

I had to take a look at this a bit further. Seems silly that it's giving an error, especially since I've never used Drupal to either rotate or filter an image since I've been using it. So if I look for the instances where it's used:

$ grep -ir imagefilter *
modules/simpletest/tests/image.test:    // Systems using non-bundled GD2 don't have imagefilter. Test if available.
modules/simpletest/tests/image.test:    if (function_exists('imagefilter')) {
modules/simpletest/tests/image.test:        // Transparent GIFs and the imagefilter function don't work together.
modules/image/image.install:      if (function_exists('imagefilter') && function_exists('imagerotate')) {
modules/system/image.gd.inc:  // PHP installations using non-bundled GD do not have imagefilter.
modules/system/image.gd.inc:  if (!function_exists('imagefilter')) {
modules/system/image.gd.inc:    watchdog('image', 'The image %file could not be desaturated because the imagefilter() function is not available in this PHP installation.', array('%file' => $image->source));
modules/system/image.gd.inc:  return imagefilter($image->resource, IMG_FILTER_GRAYSCALE);

$ grep -ir imagerotate *
modules/simpletest/tests/image.test:    // Systems using non-bundled GD2 don't have imagerotate. Test if available.
modules/simpletest/tests/image.test:    if (function_exists('imagerotate')) {
modules/image/image.install:      if (function_exists('imagefilter') && function_exists('imagerotate')) {
modules/system/image.gd.inc:  // PHP installations using non-bundled GD do not have imagerotate.
modules/system/image.gd.inc:  if (!function_exists('imagerotate')) {
modules/system/image.gd.inc:    watchdog('image', 'The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', array('%file' => $image->source));
modules/system/image.gd.inc:  $image->resource = imagerotate($image->resource, 360 - $degrees, $background);

It really boils down to two lines that require it for one module. I think these are the Imagemagick equivalents:

http://ca2.php.net/manual/en/function.imagick-medianfilterimage.php
http://ca2.php.net/manual/en/function.imagick-rotateimage.php

So shouldn't we just allow for that if it's a matter of two functional lines in the code? This is just a partial patch, as it just deals with proposed changes to include rotateimage support and doesn't deal with the a lot of stuff. Just a proof of concept at this point.

Either way I support this being made a warning and not an error on the Status page as per:
http://drupal.org/node/758628#comment-2805856

I should probably make a new issue to talk about imagemagick support.

coderintherye’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs work » Needs review
FileSize
1.63 KB

Attached is a patch which basically makes these warnings instead of errors as per #16 but including Randy's request that this apply to both image.install and color.install

My anecdotal opinion, I've run dozens if not hundreds of sites now and never used image rotation or desaturation effects, but even for those who do use such effects, this shouldn't be an error, it should be a warning, otherwise you get confused users (which you will find in the issue queue) wondering why they have this even though it in no way prevents them from installing Drupal. We had so much hubbub in the D7 release process about issues not being critical if they don't affect the core usage of Drupal, and I think we should apply the same standards to what the Status Report is outputting. You can run a Drupal site without needing these GD effects, and moreover you may never need them.

My reason for wanting this is so I can use drush nagios-check requirements for a sanity check, but now looks like I'll have to reproduce that functionality (in lieu of hacking core).

mgifford’s picture

FileSize
76.57 KB
87.02 KB

Patch applies nicely. Looks better.

+1 & Thanks!

rfay’s picture

Issue tags: +Needs backport to D7

Marking needs backport. Thanks for the effort here.

sun’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Makes sense to have these not be as severe as they are now. Rotate, especially, is just showing off. :)

Committed to 8.x and 7.x. Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -Needs backport to D7

Automatically closed -- issue fixed for 2 weeks with no activity.