Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

php iptcembed corrupting image size info

Posted on 2009-04-06
1
Medium Priority
?
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

609 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