我试图拍摄一张照片并创建一个缩略图,而不丢失包含版权信息和其他信息的IPTC信息。我正在使用GD脚本来调整大小,这当然会导致IPTC数据的丢失,因为它创建了一个完整的新文件,而不是实际调整原始文件的大小。因此,我的解决方案是从原始图像中提取IPTC数据,然后将其嵌入缩略图中。到目前为止,一切都运行良好,除了IPTC数据没有被复制之外,缩略图是生成的。我的代码片段在下面。有人能看到我失踪的任何东西吗?这是基于PHP手册中iptcembed()中的示例。哦,是的,我在Zend框架内工作,但是除了注册表来处理配置之外,这是非常简单的OOP代码。谢谢!
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);
}
}发布于 2011-04-09 14:21:23
我认为iptcembed会自动保存文件,这意味着php.net手动示例是错误的:
如果
返回值,如果成功和假脱机标志低于2,则不会以字符串的形式返回JPEG,错误时为FALSE。
请参阅http://php.net/iptcembed
https://stackoverflow.com/questions/5508602
复制相似问题