使用 PHP 将元数据添加到 PNG 图像 [英] Add metadata to PNG image using PHP

查看:49
本文介绍了使用 PHP 将元数据添加到 PNG 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 php 将元数据(例如关键字)添加到多个 png 图像中?我已经将图像存储在我的数据库中,我想对它们相应的关键字做同样的事情,但我还没有找到任何有用的使用 php 的建议.谢谢

Is there a way to add metadata (such as keywords) to several png images using php? I have stored the images in my database, and I want to do the same with their corresponding keywords, but I haven't found any helpful suggestions using php yet. Thanks

图片.php

<!DOCTYPE html>
<html lang="en">
<head>
	<title>Upload Images</title>
</head>
 <body>
	<form action="tags.php" method="POST" enctype="multipart/form-data" >
		<p>Select Image (one or multiple):</p>
		<input type="hidden" name="MAX_FILE_SIZE" value="536870912"/>
		<input type="file" name="image[]" accept="image/png" accept="image/jpg" accept="image/jpeg" accept="image/gif" multiple="multiple" />
		<input type="submit" value="Upload file" name="submit" />

	</form>
 </body>
</html>

tags.php(猛禽的回答)

tags.php (Raptor's answer)

<?php
include('../config.php');

$image = new Imagick();
$image->readImage("C:/xampp/htdocs/cmanager/uploads");
$image->setImageProperty('keywords', 'Imagick');

print($image->getImageProperty('keywords'));

推荐答案

你需要 ImageMagick 的 setImageProperty() 有助于实现您的目标.

You need ImageMagick's setImageProperty() help to achieve your goal.

<?php
$image = new Imagick();
$image->newImage(300, 200, "black"); // or load your PNG into Imagick

$image->setImageProperty('keywords', 'Imagick');
echo $image->getImageProperty('keywords');
?>

需要 PHP 编译 ImageMagick 6.3.2+.

Require PHP to compile against ImageMagick 6.3.2+.

或者,您可以使用此处所示的代码解析 PNG 的元数据.试试看.

Alternatively, you can parse the PNG's metadata with the codes shown here. Try it out.

最后,如果您打算编辑 EXIF 数据,您可以使用 EXIF 函数.

Last, if you intend to edit EXIF data instead, you can use the EXIF functions.

这篇关于使用 PHP 将元数据添加到 PNG 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆