[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 520
  • Last Modified:

php iptcembed corrupting image size info

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
Hube02
Asked:
Hube02
1 Solution
 
Hube02Author Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now