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

我很难理解如何通过Python更改JPEG文件的标签。 我所指的“标签”是任何任意文件的描述属性下的标签,其中评论,主题和评分也将被发现。 我不确定是否有一个类似于文件名重命名function的.osfunction可以做到这一点,或者如果这种改变标签的操作属于JPEG Metadata / EXIFDATA操作的类别。

比方说,我想通过Python为JPEG图像添加3个标签,这些标签是BLUE,SQUARE和9的标签。手动我会去文件,通过右击文件来查看描述属性来查看它的标签,或点击底部栏菜单,然后点击标签,然后在文本框中inputBLUE,SQUARE和9,每个标签后面用分号分隔。 使用Python,我需要一个脚本,可以将这些单独的标记插入到JPEG的描述属性中,以便使这个过程更轻松,如果我要为多个JPEG文件迭代地执行此操作。

我怀疑这会需要用Python进行编程的繁重知识,但是同时我的问题的特殊性似乎没有一个简单的解决scheme。 我似乎无法find一个半清晰或直截了当的答案,因为当谈到使用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 Heres所有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