【发布时间】:2017-07-12 16:33:43
【问题描述】:
我的系统接受以下格式的图像文件:png、jpg、gif。同一个文件可能带有不同的元数据集到达我的系统,我需要唯一标识它们,无论他们的元数据。
我尝试使用 PHP 模块 Imagick,读取图像,去除元数据,然后对它们进行哈希处理。
// example_image: https://ibb.co/bVkanv
$image_path = ‘example.jpg’;
$stripped_image_path = ‘stripped_example.jpg’;
$img = new Imagick($image_path);
$img->stripImage();
$img->writeImage($stripped_image_path);
$image_hash = sha1_file($stripped_image_path);
尽管如此,这种方法并不能正常工作,因为哈希值不同:
// example_image: https://ibb.co/bVkanv
$original_image = ‘Example.jpg’;
$image1_path = ‘example1.jpg’;
$image2_path = ‘example2.jpg’;
$stripped_image1_path = ‘stripped_example1.jpg’;
$stripped_image2_path = ‘stripped_example2.jpg’;
$imagick_1 = new Imagick($original_image);
$imagick_1->setImageProperty('Exif:Make', 'Imagick_1');
$imagick_1->writeImage($image1_path);
$imagick_2 = new Imagick($original_image);
$imagick_2->setImageProperty('Exif:Make', 'Imagick_2');
$imagick_2->writeImage($image2_path);
// Now example1.jpg and example2.jpg SHOULD be the same image with different metadata
$imagick_1 = new Imagick($image1_path);
$imagick_1->stripImage();
$imagick_1->writeImage($stripped_image1_path);
$imagick_2 = new Imagick($image2_path);
$imagick_2->stripImage();
$imagick_2->writeImage($stripped_image2_path);
$hash = sha1_file($image_path);
$stripped_hash1 = sha1_file($stripped_image1_path);
$stripped_hash2 = sha1_file($stripped_image2_path);
$hash
88f454a5f768d633f9d5b8fbba73cdc9dfa46f59
$stripped_hash1
fd385aa6ebcf8018a725598df945f925d8e05d58
$stripped_hash2
d9c9bca4f4433556d5c4c0d62ce06de06920e69b
我怎样才能实现我的目标?
【问题讨论】:
-
您应该尝试自己编写代码。在doing more research 之后,如果您有问题发布您尝试过的方法,并清楚地解释什么不起作用,并提供a Minimal, Complete, and Verifiable example。阅读How to Ask 一个好问题。请务必take the tour 并阅读this。
-
@JayBlanchard 完成!