How can I access and change the description property of a JPEG image tag in Windows 7 File Explorer using Python?

I'm having a hard time understanding how I can change the tags of a JPEG file via Python. The "tags" by which I mean refer to the description properties of any arbitrary file in which comments, topics and ratings will also be found. I'm not sure if there is a .os function similar to the rename file name function that can do this, or if such a tag changing operation would fall under the category of JPEG / EXIFDATA metadata manipulation.

Let's say for example I want to add 3 tags to a JPEG image via Python, the ones that are BLUE, SQUARE and 9. Manually, I would go to the file, accessing the description properties, right-clicking the file to view its tags, or click the bottom panel menu and click tags to then enter BLUE, SQUARE and 9 in the text box with a semicolon after each individual tag. With Python, I would need a script that can insert these individual tags into the JPEG description properties to make the process less painful if I were to iterate over multiple JPEG files.

I doubt this would require any serious programming knowledge with Python, but at the same time, the specifics of my problem seem to elude simple resolution. I can't seem to find a semi-clear or straightforward answer, since I'm a bit green when it comes to programming with python in general.

Any help would be very, very helpful. I am using Python 3.5.2. by the way.

+3


source to share


1 answer


So here's my revised answer. So all the information in the jpg is metadata stored with the number "id", so for example the 0th description area you are looking for represents a table.

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'

      

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

So, to change like a theme, all you have to do is ...

pip install piexif

      



This works with 2.7 and 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() 

      

Hope it helps: D Here is a list of all ids

<< 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

      

0


source







All Articles