Solved

php iptcembed corrupting image size info

Posted on 2009-04-06
1
504 Views
Last Modified: 2012-08-14
I am using iptcembed() to imbed IPTC data into JPEG images.

Occasionally the iptcembed() function corrupts the data that would normally be retrieved using getimagesize().

When this happens, the IPTC data is still available, but the function getimagesize() returns false, as if the file is not an image. This does not corrupt the image and the image still displays correctly.

My question is, does anyone know how, or if it is possible to restore this information when it becomes corrupted?
0
Comment
Question by:Hube02
1 Comment
 
LVL 18

Accepted Solution

by:
Hube02 earned 0 total points
ID: 24086114
Well, after sleeping on it I came up with a solution to the problem that seems to work. After writing the IPTC data to the image I check for the presence of size info by using the getimagesize() function. If this reports false then I create a new image using imagecreatefromjpeg().

Spinets of the code I'm using are below, I would appreciate any suggestions on improvement...

// function to rebuild image
 

    function rebuildImage() {

      $image = imagecreatefromjpeg($this->image);

      imagejpeg($image, $this->image, 100);

      $this->IPTCwrite();

    }
 

// section of code that checks for corruption
 

        if ($content = iptcembed($this->binary(), $filename, $mode)) {  

          if ($fp = fopen($filename, "w")) {

            fwrite($fp, $content);

            fclose($fp);

            if (getimagesize($filename)) {

              $success = true;

            } else {

              // writing data corrupted size info

              $this->rebuildImage();

            }

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now