I am trying to take a photograph and create a thumbnail without losing the IPTC info that contains copyright info and other information. I am scripting using GD for the resize which of course results in the loss of the IPTC data since it creates an entire new file, not actually resizing the original. So, my solution was to extract the IPTC data from the original image and then embed it in the thumbnail. As of now, everything runs fine and the thumbnail is generated except the IPTC data is not copied over. My code snippet is below. Can anyone see anyhting I am missing? This is based off of the examples in the PHP manual for iptcembed(). Oh yeah, I am working within the Zend Framework but apart from the Registry to handle the config, this is pretty straightforward OOP code. Thanks!
public function resizeImage($image, $size)
{
// Get Registry
$galleryConfig = Zend_Registry::get('gallery_config');
$path = APPLICATION_PATH . $galleryConfig->paths->mediaPath . $image->path . '/';
$file = $image->filename . '.' . $image->extension;
$newFilename = $image->filename . '_' . $size . '.' . $image->extension;
// Get Original Size
list($width, $height) = getimagesize($path . $file);
// Check orientation, create scalar
if($width > $height){
$scale = $width / $size;
}else{
$scale = $height / $size;
}
// Set Quality
switch($size){
case ($size <= 200):
$quality = 60;
break;
case ($size > 200 && $size <= 600):
$quality = 80;
break;
case ($size > 600):
$quality = 100;
break;
}
// Recalculate new sizes with default ratio
$new_width = round($width * (1 / $scale));
$new_height = round($height * (1/ $scale));
// Resize Original Image
$imageResized = imagecreatetruecolor($new_width, $new_height);
$imageTmp = imagecreatefromjpeg ($path.$file);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Save File
$complete = imagejpeg($imageResized, $path . $newFilename, $quality);
// Copy IPTC info into new file
$imagesize = getImageSize($path . $file, $info);
if(isset($info['APP13'])){
$content = iptcembed($info['APP13'], $path . $newFilename);
$fw = fopen($path . $newFilename , 'wb');
fwrite($fw, $content);
fclose($fw);
}
}