为图像添加注释时,为什么图像的大小会减小? [英] Why does the size of my image decrease when I add a comment to an image?

查看:250
本文介绍了为图像添加注释时,为什么图像的大小会减小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的图片中添加评论,并减少了文件大小。我有三个图像都有不同的文件大小和不同的用户评论EXIF数据。没有评论的图像是最大的。为什么没有评论的图像最大?通过编辑EXIF数据,我压缩或改变图像。

I tried to add a comment to my image and it decreased the filesize. I have three images all have different file sizes and different user comment EXIF data .The image without the comment is the largest. Why is the image without the comment the largest? By editing the EXIF data am I compressing or altering the image.


  • 我的图像是2007KB。它不包含
    中exif数据的用户注释。

  • 当我通过属性页面(Windows 10)添加评论(我喜欢土豆只是一个测试评论)
    时,它减少了我的
    的大小图片到1991KB。

  • 当我使用python脚本添加用户注释(blah blah
    blah)时,它会将文件大小减小到726KB。

除了文件大小和EXIF数据外,我发现图像中没有其他差异。我放大了图像,没有注意到差异。我查看了其余的EXIF数据并且存在一些差异。区别在于

Apart from the filesize and EXIF data I've found no other differences in the images. I've zoomed in on the images and haven't noticed differences. I've looked through the rest of EXIF data and there are some differences. The differences are in


  • EXIF InteroperabilityOffset

  • EXIF OffsetSchema

  • EXIF Padding

  • GPS GPSProcessingMethod

  • 图像ExifOffset

  • 图像GPSInfo

  • 图片填充

  • 图片XPComment

  • 互操作性互操作性指数

  • 互操作性互操作性版本

  • 缩略图JPEGInterchangeFormat

  • 缩略图JPEGInterchangeFormatLength。

  • EXIF InteroperabilityOffset
  • EXIF OffsetSchema
  • EXIF Padding
  • GPS GPSProcessingMethod
  • Image ExifOffset
  • Image GPSInfo
  • Image Padding
  • Image XPComment
  • Interoperability InteroperabilityIndex
  • Interoperability InteroperabilityVersion
  • Thumbnail JPEGInterchangeFormat
  • Thumbnail JPEGInterchangeFormatLength.

如果您还有其他问题请告诉我。

If you have any other questions please let me know.

这是python脚本:

Here is the python script:

import piexif
import os.path 
from PIL import Image

def writeExifComment(filename,comment):

    im = Image.open(filename)
    fileExtension = os.path.splitext(filename)[1]
    exif_dict = piexif.load(im.info["exif"])
    exif_dict["Exif"][piexif.ExifIFD.UserComment] = comment
    exif_bytes = piexif.dump(exif_dict)
    im.save(filename, 'jpeg', exif=exif_bytes)
    im.close()

def readExifComment(filename):

    data = piexif.load(filename)
    exif = data['Exif']
    comment = exif.get(37510, '').decode('UTF-8')
    return comment

filename = '1.jpg'

writeExifComment(filename,"blah blah blah")
print(readExifComment(filename))


推荐答案

保存图像时( im.save(filename,'jpeg',exif = exif_bytes))使用PIL库,您可以使用默认质量。这个默认为75 (这意味着 - 如果您的原始图像质量更高 - 期间保存 - 图像的质量会降低,图像的大小也会减少。

When you save an image (im.save(filename, 'jpeg', exif=exif_bytes)) using PIL library there is a default quality that you use. This default is 75 (which means - if your original image is in higher quality - during the saving - the quality of the image will decrease, and also the size of the image.

您可以使用 quality = X更改质量(X = 1-> 95,你应该避免95以上的任何数字):

You can change the quality by using quality=X (X = 1->95, You should avoid any number above 95):

im.save(filename, 'jpeg', exif=exif_bytes, quality=95)




<请注意,它可能会创建一个尺寸大于原始图像大小的图像。

Note that it might create an image with higher size than your original image's size.

关于原始图像的堆栈有一个问题图像质量,你可以在这里查看更多:用Python确定JPG质量(PIL)

There is a question on stack regarding the original quality of image, you can check more here: Determining JPG quality in Python (PIL)

这篇关于为图像添加注释时,为什么图像的大小会减小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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