以下将删除jpeg文件的所有EXIF数据。这将复制没有EXIF的原始文件,并删除旧文件。使用100质量不会丢失图片的任何质量细节。
$path = "/image.jpg";
$img = imagecreatefromjpeg ($path);
imagejpeg ($img, $path, 100);
imagedestroy ($img);
(可以在此处找到该图的简单近似值)
0
以下将删除jpeg文件的所有EXIF数据。这将复制没有EXIF的原始文件,并删除旧文件。使用100质量不会丢失图片的任何质量细节。
$path = "/image.jpg";
$img = imagecreatefromjpeg ($path);
imagejpeg ($img, $path, 100);
imagedestroy ($img);
(可以在此处找到该图的简单近似值)
0
使用ImageMagick在PHP中执行此操作的快速方法(假定已安装并启用它)。
<?php
$images = glob('*.jpg');
foreach($images as $image)
{
try
{
$img = new Imagick($image);
$img->stripImage();
$img->writeImage($image);
$img->clear();
$img->destroy();
echo "Removed EXIF data from $image. \n";
} catch(Exception $e) {
echo 'Exception caught: ', $e->getMessage(), "\n";
}
}
?>
0
使用gd
在新的图像中重新创建图像的图形部分,并用其他名称保存。
参见PHP gd
使用新的Imagick功能。
开启图片:
<?php
$incoming_file = '/Users/John/Desktop/file_loco.jpg';
$img = new Imagick(realpath($incoming_file));
确保在图像中保留所有ICC配置文件
$profiles = $img->getImageProfiles("icc", true);
然后剥离图像,然后将配置文件放回去
$img->stripImage();
if(!empty($profiles)) {
$img->profileImage("icc", $profiles['icc']);
}
来自此PHP页面 ,请参见Max Eremin的注释。
0
我也在寻找解决方案。最后,我使用PHP重写了删除所有Exif数据的JPEG。我不需要任何目的。
此选项有几个优点...
还要注意有关使用imagecreatefromjpeg的注意事项:我尝试了此操作,并且文件变大了。如果将质量设置为100,则文件将更大,因为图像已经过重新采样,然后以无损方式存储。如果您不使用质量100,则会失去图像质量。避免重采样的唯一方法是不使用imagecreatefromjpeg。
这是我的职能...
/**
* Remove EXIF from a JPEG file.
* @param string $old Path to original jpeg file (input).
* @param string $new Path to new jpeg file (output).
*/
function removeExif($old, $new)
{
// Open the input file for binary reading
$f1 = fopen($old, 'rb');
// Open the output file for binary writing
$f2 = fopen($new, 'wb');
// Find EXIF marker
while (($s = fread($f1, 2))) {
$word = unpack('ni', $s)['i'];
if ($word == 0xFFE1) {
// Read length (includes the word used for the length)
$s = fread($f1, 2);
$len = unpack('ni', $s)['i'];
// Skip the EXIF info
fread($f1, $len - 2);
break;
} else {
fwrite($f2, $s, 2);
}
}
// Write the rest of the file
while (($s = fread($f1, 4096))) {
fwrite($f2, $s, strlen($s));
}
fclose($f1);
fclose($f2);
}
代码很简单。打开输入文件进行读取,输出文件进行写入,然后开始读取输入文件。它从一个到另一个的数据。一旦到达EXIF标记,它将读取EXIF记录的长度,并跳过该字节数。然后,通过读取和写入剩余数据继续进行。
0
这是最简单的方法:
$images = glob($location.'/*.jpg');
foreach($images as $image) {
$img = imagecreatefromjpeg($image);
imagejpeg($img,$image,100);
}
0
我完全误解了你的问题。
您可以使用某些命令行工具来完成此工作。或编写自己的php扩展名即可。看看这个有用的库: http : //www.sno.phy.queensu.ca/~phil/exiftool/
干杯,
vfn
0
function remove_exif($in, $out)
{
$buffer_len = 4096;
$fd_in = fopen($in, 'rb');
$fd_out = fopen($out, 'wb');
while (($buffer = fread($fd_in, $buffer_len)))
{
// \xFF\xE1\xHH\xLLExif\x00\x00 - Exif
// \xFF\xE1\xHH\xLLhttp:// - XMP
// \xFF\xE2\xHH\xLLICC_PROFILE - ICC
// \xFF\xED\xHH\xLLPhotoshop - PH
while (preg_match('/\xFF[\xE1\xE2\xED\xEE](.)(.)(exif|photoshop|http:|icc_profile|adobe)/si', $buffer, $match, PREG_OFFSET_CAPTURE))
{
echo "found: '{$match[3][0]}' marker\n";
$len = ord($match[1][0]) * 256 + ord($match[2][0]);
echo "length: {$len} bytes\n";
echo "write: {$match[0][1]} bytes to output file\n";
fwrite($fd_out, substr($buffer, 0, $match[0][1]));
$filepos = $match[0][1] + 2 + $len - strlen($buffer);
fseek($fd_in, $filepos, SEEK_CUR);
echo "seek to: ".ftell($fd_in)."\n";
$buffer = fread($fd_in, $buffer_len);
}
echo "write: ".strlen($buffer)." bytes to output file\n";
fwrite($fd_out, $buffer, strlen($buffer));
}
fclose($fd_out);
fclose($fd_in);
}
它是从命令行调用的原型。
0
有什么方法可以使用PHP从JPG删除EXIF数据?我听说过PEL,但我希望有一种更简单的方法。我正在上传将在线显示的图像,并希望删除EXIF数据。
谢谢!
编辑:我不/不能安装ImageMagick。