?
Solved

php iptcembed corrupting image size info

Posted on 2009-04-06
1
Medium Priority
?
515 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 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