I have a php script that uses getimagesize. The new server is running 4.3.4, and all file permissions are the same as they were on our old server.

But what happens, is getimagesize fails for about 50-75% of our images that I run it on... it used to work flawlessly in an older php version.

For most of these images, it simply returns NO values. The rest of the images, it works fine. Specifically, I look for the width and height of the image.

Now the funny thing, is that I download the images that don't work, open them in photoshop and save the file again... OVER ITSELF, with the same file type, extension, name etc. Then I re-upload it and everything works fine!

Do you have any ideas what could be causing this, or maybe some ideas on how I can better find where the breakdown is?

    If they're jpg files then I suspect they've been saved in CMYK mode. One of my clients does that all the time. Try opening one of them in IE. If it fails then its likely to be the problem.

      The crappy thing though is that ALL of these images, whether they're not readable by php or not, is that they all show fine in any web browser.

        The bogoakcastlepin.jpg image is set to 96dpi .. that might make a difference I guess.

          I guess I need to find out how php handles these images differently... what is causing it?

          getimagesize works fine on these images:

          http://www.jazbot.com/Jazz/Vintage/polarbears.jpg
          http://www.jazbot.com/Jazz/Vintage/goofusliliesvalley0304.jpg
          http://www.jazbot.com/Jazz/Plastics/lucitepastelbeads2.jpg

          but fails to return ANY values on these:

          http://www.jazbot.com/Jazz/Designer/regencycatseyepin.jpg
          http://www.jazbot.com/Jazz/Vintage/bogoakcastlepin.jpg

          As I said before, permissions are the same, all were uploaded via ftp using the same format, etc.

          What do the first three have that the second two do not?

            All five work fine for me (though I'm using PHP5RC1):

            bogoakcastlepin.jpg
            Array
            (
                [0] => 293
                [1] => 268
                [2] => 2
                [3] => width="293" height="268"
                [bits] => 8
                [channels] => 3
                [mime] => image/jpeg
            )
            
            
            goofusliliesvalley0304.jpg
            Array
            (
                [0] => 240
                [1] => 200
                [2] => 2
                [3] => width="240" height="200"
                [bits] => 8
                [channels] => 3
                [mime] => image/jpeg
            )
            
            
            lucitepastelbeads2.jpg
            Array
            (
                [0] => 340
                [1] => 207
                [2] => 2
                [3] => width="340" height="207"
                [bits] => 8
                [channels] => 3
                [mime] => image/jpeg
            )
            
            
            polarbears.jpg
            Array
            (
                [0] => 340
                [1] => 149
                [2] => 2
                [3] => width="340" height="149"
                [bits] => 8
                [channels] => 3
                [mime] => image/jpeg
            )
            
            
            regencycatseyepin.jpg
            Array
            (
                [0] => 324
                [1] => 344
                [2] => 2
                [3] => width="324" height="344"
                [bits] => 8
                [channels] => 3
                [mime] => image/jpeg
            )
            

            I do remember that some old versions of PHP had trouble with certain JPEG images (typically those generated by certain models of digital camera); an upgrade fixed that. I don't recall what version that was though - it might have been as low as 4.2.3.

            As onion2k notes, the only visible difference between the images that work and the images that don't is the dpi.

            Another difference is that the two that fail have over 45000 bytes of junk attached (stuff like thumbnail images and so on that Photoshop stuck in there), which effectively double their file sizes; the others have less.

            bogoakcastlepin...Cleaned 45269 bytes
            goofusliliesvalley0304...Cleaned 41045 bytes
            lucitepastelbeads2...Cleaned 29891 bytes
            polarbears...Cleaned 21827 bytes
            regencycatseyepin...Cleaned 46421 bytes
            
              a month later

              im having a similar problem, since moving servers this week to (what I assume is the latest) PHP, no getimage size's work at all

              all the jpegs involved were uploaded via a form and resized in php by some image functions I have.

              I've tried absolute path and relative but getimagesize just won't work =(

              any other way to confirm if a file exists and get it's size attributes?

                Write a Reply...