惠普服务器显示thumbnail,PHP: exif_thumbnail - Manual PHP中文手册 PHP中国镜像 php 国内镜像...

这段代码演示了如何利用PHPExifLibrary在没有EXIF缩略图的JPEG图像中创建一个新的缩略图。如果图像原本没有IFD1(即缩略图),它会创建一个,并将缩略图写回到源文件的EXIF数据中。如果已存在IFD1,代码则不会覆盖原有缩略图。
摘要由CSDN通过智能技术生成

If you've edited the image with image editing software and it no longer contains an exif thumbnail, I've created a script that will add one back into it, using the "PHP Exif Library": http://pel.sourceforge.net/index.php

require_once('../PEL/PelIfd.php');$fullpath='images/DSC_0013c.JPG';# path of source image (does not contain an exif thumbnail)$jpeg= newPelJpeg($fullpath);$exif=$jpeg->getExif();$tiff=$exif->getTiff();$ifd0=$tiff->getIfd();# need this so that we can later link it to the new IFD$ifd1=$ifd0->getNextIfd();

if (!$ifd1) {# Only create thumbnail if one doesn't exist (i.e. there is no IFD1)$ifd1= newPelIfd(1);$ifd0->setNextIfd($ifd1);# point ifd0 to the new ifd1 (or else ifd1 will not be read)$original=ImageCreateFromString($jpeg->getBytes());# create image resource of original$orig_w=imagesx($original);$orig_h=imagesy($original);$wmax=160;$hmax=120;

if ($orig_w>$wmax||$orig_h>$hmax) {$thumb_w=$wmax;$thumb_h=$hmax;

if ($thumb_w/$orig_w*$orig_h>$thumb_h)$thumb_w=round($thumb_h*$orig_w/$orig_h);# maintain aspect ratioelse$thumb_h=round($thumb_w*$orig_h/$orig_w);

}

else {# only set the thumb's size if the original is larger than 'wmax'x'hmax'$thumb_w=$orig_w;$thumb_h=$orig_h;

}# create image resource with thumbnail sizing$thumb=imagecreatetruecolor($thumb_w,$thumb_h);## Resize original and copy to the blank thumb resourceimagecopyresampled($thumb,$original,0,0,0,0,$thumb_w,$thumb_h,$orig_w,$orig_h);# start writing output to bufferob_start();# outputs thumb resource contents to bufferImageJpeg($thumb);# create PelDataWindow from buffer thumb contents (and end output to buffer)$window= newPelDataWindow(ob_get_clean());

if ($window) {$ifd1->setThumbnail($window);# set window data as thumbnail in ifd1$outpath=$fullpath;# overwrite original jpg filefile_put_contents($outpath,$jpeg->getBytes());# write everything to output filename

            # Show thumbnail in file:echo'If you see this, it did not work
';

}

}

else {

echo'ifd1 already exists! (IFD1 is where the thumbnail is stored)
';

}?>

echo($imgdat);?>

If you have a lot of such files, you can easily make a script that searches them out and adds thumbnails to their exif.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值