python - 如何使用 Python 在 Windows 7 文件资源管理器中访问和更改 JPEG 图像的标签描述属性?

标签 python windows file tags rename

我很难理解如何通过 Python 更改 JPEG 文件的标签。我指的“标签”是指任何任意文件的描述属性下的标签,其中还可以找到评论、主题和评级。我不确定是否有类似于文件名重命名功能的 .os 功能可以执行此操作,或者这种更改标签的操作是否属于 JPEG 元数据/EXIFDATA 操作的类别。

例如,我想通过 Python 向 JPEG 图像添加 3 个标签,即标签 BLUE、SQUARE 和 9。我会手动转到文件,通过右键单击文件查看其标签,或单击底部栏菜单,然后单击标签,然后在文本框中输入 BLUE、SQUARE 和 9,每个单独的标签后有一个分号。使用 Python 时,我需要一个脚本来将这些单独的标签注入(inject)到 JPEG 的描述属性中,以便在我为多个 JPEG 文件迭代执行此操作时减少痛苦。

我怀疑这是否需要任何熟练的 Python 编程知识,但与此同时,我的问题的特殊性似乎无法轻松解决。我似乎无法找到一个半明确或直接的答案,因为在使用 python 进行一般编程时我有点新手。

任何帮助都会非常非常有用。我正在使用 Python 3.5.2。顺便说一下。

最佳答案

所以,这是我修改后的答案。 因此,jpg 中的所有信息都是用“id”编号存储的元数据,例如第 0 是您要查找的描述区域,这里是一个表。

0th:
283 = (720000, 10000)
296 = 2
34665 = 11444
306 = b'2011:08:22 21:39:05'
270 = b''
271 = b'OLYMPUS IMAGING CORP.'
272 = b'E-P1'
305 = b'Adobe Photoshop CS5 Windows'
274 = 1
33432 = b'Robin Parmar'
282 = (720000, 10000)
315 = b'Robin Parmar'

来源http://www.theatreofnoise.com/2016/10/how-to-retrieve-photo-metadata-in-python.html

所以要像主题一样改变你需要做的就是......

pip install piexif

这适用于 2.7 和 3

import piexif

def insert_sample():
    zeroth_ifd = {270: "test"}
    exif_bytes = piexif.dump({"0th":zeroth_ifd})
    piexif.insert(exif_bytes,'img.jpg')

insert_sample() 

希望对您有所帮助 :D 这是所有 ID 的列表

<< Inspect piexif >>

11 = ProcessingSoftware
18246 = Rating
18249 = RatingPercent
254 = NewSubfileType
255 = SubfileType
256 = ImageWidth
257 = ImageLength
258 = BitsPerSample
259 = Compression
262 = PhotometricInterpretation
263 = Threshholding
264 = CellWidth
265 = CellLength
266 = FillOrder
269 = DocumentName
270 = ImageDescription
271 = Make
272 = Model
273 = StripOffsets
274 = Orientation
277 = SamplesPerPixel
278 = RowsPerStrip
279 = StripByteCounts
282 = XResolution
283 = YResolution
284 = PlanarConfiguration
290 = GrayResponseUnit
291 = GrayResponseCurve
292 = T4Options
293 = T6Options
296 = ResolutionUnit
301 = TransferFunction
305 = Software
306 = DateTime
315 = Artist
316 = HostComputer
317 = Predictor
318 = WhitePoint
319 = PrimaryChromaticities
320 = ColorMap
321 = HalftoneHints
322 = TileWidth
323 = TileLength
324 = TileOffsets
325 = TileByteCounts
32781 = ImageID
330 = SubIFDs
332 = InkSet
333 = InkNames
334 = NumberOfInks
33421 = CFARepeatPatternDim
33422 = CFAPattern
33423 = BatteryLevel
33432 = Copyright
33434 = ExposureTime
336 = DotRange
337 = TargetPrinter
338 = ExtraSamples
339 = SampleFormat
340 = SMinSampleValue
341 = SMaxSampleValue
342 = TransferRange
343 = ClipPath
34377 = ImageResources
344 = XClipPathUnits
345 = YClipPathUnits
346 = Indexed
34665 = ExifTag
34675 = InterColorProfile
347 = JPEGTables
34853 = GPSTag
34857 = Interlace
34858 = TimeZoneOffset
34859 = SelfTimerMode
351 = OPIProxy
37387 = FlashEnergy
37388 = SpatialFrequencyResponse
37389 = Noise
37390 = FocalPlaneXResolution
37391 = FocalPlaneYResolution
37392 = FocalPlaneResolutionUnit
37393 = ImageNumber
37394 = SecurityClassification
37395 = ImageHistory
37397 = ExposureIndex
37398 = TIFFEPStandardID
37399 = SensingMethod
40091 = XPTitle
40092 = XPComment
40093 = XPAuthor
40094 = XPKeywords
40095 = XPSubject
50341 = PrintImageMatching
50706 = DNGVersion
50707 = DNGBackwardVersion
50708 = UniqueCameraModel
50709 = LocalizedCameraModel
50710 = CFAPlaneColor
50711 = CFALayout
50712 = LinearizationTable
50713 = BlackLevelRepeatDim
50714 = BlackLevel
50715 = BlackLevelDeltaH
50716 = BlackLevelDeltaV
50717 = WhiteLevel
50718 = DefaultScale
50719 = DefaultCropOrigin
50720 = DefaultCropSize
50721 = ColorMatrix1
50722 = ColorMatrix2
50723 = CameraCalibration1
50724 = CameraCalibration2
50725 = ReductionMatrix1
50726 = ReductionMatrix2
50727 = AnalogBalance
50728 = AsShotNeutral
50729 = AsShotWhiteXY
50730 = BaselineExposure
50731 = BaselineNoise
50732 = BaselineSharpness
50733 = BayerGreenSplit
50734 = LinearResponseLimit
50735 = CameraSerialNumber
50736 = LensInfo
50737 = ChromaBlurRadius
50738 = AntiAliasStrength
50739 = ShadowScale
50740 = DNGPrivateData
50741 = MakerNoteSafety
50778 = CalibrationIlluminant1
50779 = CalibrationIlluminant2
50780 = BestQualityScale
50781 = RawDataUniqueID
50827 = OriginalRawFileName
50828 = OriginalRawFileData
50829 = ActiveArea
50830 = MaskedAreas
50831 = AsShotICCProfile
50832 = AsShotPreProfileMatrix
50833 = CurrentICCProfile
50834 = CurrentPreProfileMatrix
50879 = ColorimetricReference
50931 = CameraCalibrationSignature
50932 = ProfileCalibrationSignature
50934 = AsShotProfileName
50935 = NoiseReductionApplied
50936 = ProfileName
50937 = ProfileHueSatMapDims
50938 = ProfileHueSatMapData1
50939 = ProfileHueSatMapData2
50940 = ProfileToneCurve
50941 = ProfileEmbedPolicy
50942 = ProfileCopyright
50964 = ForwardMatrix1
50965 = ForwardMatrix2
50966 = PreviewApplicationName
50967 = PreviewApplicationVersion
50968 = PreviewSettingsName
50969 = PreviewSettingsDigest
50970 = PreviewColorSpace
50971 = PreviewDateTime
50972 = RawImageDigest
50973 = OriginalRawFileDigest
50974 = SubTileBlockSize
50975 = RowInterleaveFactor
50981 = ProfileLookTableDims
50982 = ProfileLookTableData
51008 = OpcodeList1
51009 = OpcodeList2
51022 = OpcodeList3
51041 = NoiseProfile
512 = JPEGProc
513 = JPEGInterchangeFormat
514 = JPEGInterchangeFormatLength
515 = JPEGRestartInterval
517 = JPEGLosslessPredictors
518 = JPEGPointTransforms
519 = JPEGQTables
520 = JPEGDCTables
521 = JPEGACTables
529 = YCbCrCoefficients
530 = YCbCrSubSampling
531 = YCbCrPositioning
532 = ReferenceBlackWhite
60606 = ZZZTestSlong1
60607 = ZZZTestSlong2
700 = XMLPacket

关于python - 如何使用 Python 在 Windows 7 文件资源管理器中访问和更改 JPEG 图像的标签描述属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43151580/

相关文章:

html - 我在 Github 中的 CSS 文件未被 HTML 文件使用

java - 根据扩展名 Java 获取某个文件名

Python 不等于 'for' 迭代

python - 使用 TaskManager 查找在 Windows 上运行的 python 进程

windows - FTP:将文件下载到 Mac OS 并传输到 Windows Server VM - 但不起作用

c - 预览窗口后屏幕状态的 Aero 功能是什么?

Python,预期无限循环

python - 自定义代码在 virtualenv 中的哪个位置?

windows - 用于加密 Azure 服务包的加密有多可靠?

javascript - 如何使用 Node 读取 block 中的文件?