我很难理解如何通过 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/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
如何正确创建Rails迁移,以便将表更改为MySQL中的MyISAM?目前是InnoDB。运行原始执行语句会更改表,但它不会更新db/schema.rb,因此当在测试环境中重新创建表时,它会返回到InnoDB并且我的全文搜索失败。我如何着手更改/添加迁移,以便将现有表修改为MyISAM并更新schema.rb,以便我的数据库和相应的测试数据库得到相应更新? 最佳答案 我没有找到执行此操作的好方法。您可以像有人建议的那样更改您的schema.rb,然后运行:rakedb:schema:load,但是,这将覆盖您的数据。我的做法是(假设
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。