php仅删除图像中的方向exif(无图像)
我编写了一个脚本,该脚本将上传的图像在本地进行了调整,并创建了缩略图。问题是,如果某些图像垂直方向,但是在调整大小后,它们将水平旋转。
这是由于图像的Exif取向。是否有一种简单的方法可以通过PHP从图像中删除Exif?我知道它可以通过Imagick完成,但是我不能/不想安装它。
那么没有解决方案吗?
目前,我正在通过在图像编辑器中打开这样的图像并在不保留EXIF信息的情况下重新添加它来解决它。之后,当我在脚本中调整此图像大小时,结果是正确的。
因此,在调整大小之前,我只想从PHP脚本中的图像中删除EXIF。
我尝试了检查方向Exif的功能:
function removeExif($filename) {
if (function_exists('exif_read_data')) {
$exif = exif_read_data($filename);
if($exif && isset($exif['Orientation'])) {
$orientation = $exif['Orientation'];
if($orientation != 1){
// $img = new Imagick($filename);
// $img->stripImage();
// $img->writeImage($filename);
}
}
}
}
因此,我只需要用其他东西替换该Imagick零件,而无需安装任何其他库,也许使用已包含的GD或其他东西。
I wrote a script, which resizes my uploaded images in a batch locally and creates also thumbnails. The problem is, if some images are vertically oriented, but after resizing they are rotated horizontally.
This is due to exif orientation of the image. Is there a simple way to remove the orientation exif from image via PHP? I know it can be done by Imagick, but I can't/don't want to install it.
So any solution without it?
For now I am solving it by opening such an image in image editor and re-saving it without keeping exif info. After that when I resize such image in my script, the result is correct.
So I just want to remove exif from the image in my PHP script before resizing it.
I tried a function for checking the orientation exif:
function removeExif($filename) {
if (function_exists('exif_read_data')) {
$exif = exif_read_data($filename);
if($exif && isset($exif['Orientation'])) {
$orientation = $exif['Orientation'];
if($orientation != 1){
// $img = new Imagick($filename);
// $img->stripImage();
// $img->writeImage($filename);
}
}
}
}
So I just need to replace that Imagick part with something else, without installing any additional library, maybe using the already included GD or something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,所以我决定旋转图像而不是删除exif,结果具有相同的效果。因此,我检查了什么是EXIF方向值(如果有),并且根据我的使用,我只是使用
Imagerotate
,然后我调整了图像大小。结果是完美的,无需其他安装和库。Ok, so I decided to rotate the images instead of removing exif, the result has the same effect. So I check what is the exif orientation value (if any), and according that I simply use
imagerotate
and after that I resize the images. The result is perfect, no additional installs and libraries needed.