18

After updating to Mac OS X 10.10 (Yosemite) and starting Apache with PHP support, everything works as before except for any image operations on PNG files. I get a Call to undefined function imagecreatefrompng(), while any operation on JPEG files work. So GD is present, but not for PNG.

There is one line in the phpinfo() that looks like the problem: '--with-png-dir=no'

phpinfo()

The GD section from phpinfo():

Enter image description here

How do I get the included PHP to work with PNG files?

miken32
  • 42,008
  • 16
  • 111
  • 154
Rainer Mohr
  • 536
  • 1
  • 3
  • 10
  • 2
    I also upgraded to yosemite and got bit by this. I got it fixed by installing a custom php, but it isn't ideal. Anything we can do to get apple to fix gd and png in future updates? – rjcarr Oct 20 '14 at 22:53
  • 2
    in case any of the participants wonder where all the votes come from - [this question has been discussed on meta](http://meta.stackoverflow.com/questions/275103/why-did-i-fail-an-audit-for-flagging-as-off-topic-when-the-question-asks-about-f/) –  Oct 23 '14 at 15:56
  • Looks like you've upgraded either your GD library or php-gd module, to a version without PNG support compiled in. If this is the case, you'd need to recompile the offending item with the support, or upgrade to a 3rd party version with support. – Steve Shipway Oct 23 '14 at 20:50
  • 3
    Its a good question. Why on hold?? – Sanne Oct 24 '14 at 10:23
  • I don't get why this question is on hold it helps a LOT (I have similar question). I couldn't do **** without @Jpsy's answer to my Q. – Kyslik Oct 24 '14 at 11:02
  • possible duplicate of [No PNG support in PHP GD Library but has GIF and JPEG Support. How can I fix this?](http://stackoverflow.com/questions/25124761/no-png-support-in-php-gd-library-but-has-gif-and-jpeg-support-how-can-i-fix-thi) – JasonMArcher Oct 24 '14 at 21:24

3 Answers3

23

Here's another option, from the guys from liip, here. This is a PHP package that comes pre-built for Yosemite (older versions works too) but it is just one line of code:

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5

After that, everything is ready to work as expected. The configuration that cames with that installation is well suited for Symfony 2 development, but it should work just fine with other use cases.

Finally, if you need to use the updated PHP CLI, too, but you don't want to use the PHP version that comes with the OS, then you could also add to your .bash_profile or similar this line of code:

export PATH=/usr/local/php5/bin:$PATH

Patrick D'appollonio
  • 2,722
  • 1
  • 18
  • 34
  • went this way, very painless and easy to do. works like a charm – Rainer Mohr Oct 26 '14 at 16:00
  • 1
    This updates PHP which to 5.6 for the apache server, which will break a lot of codebases. How do you revert after doing this? – John Jul 27 '15 at 17:23
  • 1
    May fix the issue, but as @John noted, will break many codebases. It's also running an arbitrary hosted script, read the file before running folks – sricks Sep 10 '15 at 23:17
  • I updated the command line code to use PHP 5.5 instead of 5.6. Technically, you can choose any version between 5.3 and 5.6 using the same `install.sh` script. – Patrick D'appollonio Oct 04 '15 at 07:31
5

I had to fix this by installing PHP 5.5 again via Homebrew. Fairly painless:

https://github.com/Homebrew/homebrew-php

Installation instructions can be found here: https://github.com/Homebrew/homebrew-php#usage

I used the command brew install php55

Don't forget to update your httpd.config - instructions will be shown at the end of the homebrew install.

jtotheh
  • 51
  • 5
  • 1
    To help others, I also had to `brew update` and `brew upgrade libpng` to get this to work. – Rikki May 20 '15 at 13:37
1

As @jtotheh said, installing a complete PHP version with PNG and FreeType support compiled in is the way to go.

If you don't want to fiddle through that process, I have prepared complete step-by-step instructions as an answer to a similar question: https://stackoverflow.com/a/26505558/430742

Community
  • 1
  • 1
Jpsy
  • 20,077
  • 7
  • 118
  • 115