Solved

php iptcembed corrupting image size info

Posted on 2009-04-06
1
500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

708 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

16 Experts available now in Live!

Get 1:1 Help Now