Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#31124 closed defect (bug) (fixed)

PHP unit tests fail with fatal error, imagecreatefrompng() not defined

Reported by: iseulde Owned by: boonebgorges
Milestone: 4.2 Priority: normal
Severity: normal Version: 4.2
Component: Media Keywords:
Focuses: Cc:


PHP Fatal error: Call to undefined function imagecreatefrompng() in .../wp/svn/trunk/tests/phpunit/tests/image/editor_gd.php on line 510

Change History (12)

This ticket was mentioned in Slack in #core by iseulde. View the logs.

7 years ago

#2 @SergeyBiryukov
7 years ago

  • Component changed from General to Media
  • Milestone changed from Awaiting Review to 4.2

#3 @iseulde
7 years ago

Here are all the tests that fail and are related:

There were 5 failures:

1) Tests_Image_Functions::test_wp_save_image_file
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@


2) Tests_Image_Functions::test_inferred_mime_types
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@


3) Tests_Image_Editor_GD::test_supports_mime_type
Does not support image/png
Failed asserting that false is true.


4) Tests_Image_Editor_GD::test_image_preserves_alpha_on_resize
Failed asserting that WP_Error Object (...) is not an instance of class "WP_Error".


5) Tests_Image_Editor_GD::test_image_preserves_alpha
Failed asserting that WP_Error Object (...) is not an instance of class "WP_Error".


#4 follow-up: @boonebgorges
7 years ago

  • Keywords reporter-feedback added

Odd. You should only get that message if the PHP GD extension isn't installed. But the test suite should detect that it's not installed and skip the tests. So I'm not sure what's happening.

Do you have GD installed? $ php -i | grep "with\-gd"

#5 in reply to: ↑ 4 @SergeyBiryukov
7 years ago

Replying to boonebgorges:

Odd. You should only get that message if the PHP GD extension isn't installed.

I think it's possible for GD to be installed without PNG support.

#6 @voldemortensen
7 years ago

According to http://php.net/manual/en/image.installation.php it does seem like you have to enable png support when compiling.

We can check if PNG support is enabled with something like

$arr = gd_info();
if ( $arr['PNG Support'] === true ) { // do stuff }

to determine whether PNG tests should be run or not.

#7 @boonebgorges
7 years ago

Thanks, SergeyBiryukov and voldemortensen.

As you note, it's easy enough to do set this flag in the unit tests, but first I want to be sure that this isn't exposing a core bug. Are we doing the necessary checks in core to avoid png conversion? Or does the situation simply not arise if PNG support is not compiled with PHP?

#8 @voldemortensen
7 years ago

I haven't dug deep into everything to make sure all cases are covered, but anything using _wp_image_editor_choose has the mime type check in it. https://core.trac.wordpress.org/browser/trunk/src/wp-includes/media.php#L2491

#9 @iseulde
7 years ago

  • Keywords reporter-feedback removed

Sorry for the late reply, for some reason I'm not getting Trac emails.
Here's the output:

Configure Command =>  '/BinaryCache/apache_mod_php/apache_mod_php-93~55/Objects/php/configure'  '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-dependency-tracking' '--sysconfdir=/private/etc' '--with-apxs2=/usr/sbin/apxs' '--enable-cli' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/Library/Server/Web/Config/php' '--with-libxml-dir=/usr' '--with-openssl=/usr' '--with-kerberos=/usr' '--with-zlib=/usr' '--enable-bcmath' '--with-bz2=/usr' '--enable-calendar' '--disable-cgi' '--with-curl=/usr' '--enable-dba' '--with-ndbm=/usr' '--enable-exif' '--enable-fpm' '--enable-ftp' '--with-png-dir=no' '--with-gd' '--with-jpeg-dir=/BinaryCache/apache_mod_php/apache_mod_php-93~55/Root/usr/local' '--enable-gd-native-ttf' '--with-icu-dir=/usr' '--with-ldap=/usr' '--with-ldap-sasl=/usr' '--with-libedit=/usr' '--enable-mbstring' '--enable-mbregex' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--without-pear' '--with-pear=no' '--with-pdo-mysql=mysqlnd' '--with-mysql-sock=/var/mysql/mysql.sock' '--with-readline=/usr' '--enable-shmop' '--with-snmp=/usr' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--with-tidy' '--enable-wddx' '--with-xmlrpc' '--with-iconv-dir=/usr' '--with-xsl=/usr' '--enable-zend-multibyte' '--enable-zip' '--with-pcre-regex=/usr'

#10 @iseulde
7 years ago

Guessing --with-png-dir=no is causing the trouble?

#11 @boonebgorges
7 years ago

Looking more into this, it appears that we're only using imagecreatefrompng() to set up some test fixtures. We don't use the function in this way in core, and in the related places in core that do manipulate pngs, there are appropriate function_exists() checks. So I think we can just fix this in the tests.

#12 @boonebgorges
7 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 31510:

Better image-type support checks in image unit tests.

PHP can be compiled without support for certain image types. Our unit tests
should be sensitive to these configurations.

Fixes #31124.

Note: See TracTickets for help on using tickets.