Open MaxKrapp opened 6 years ago
having an error with: comment_string = 'Heading?' + str(hdg) + "_Sortie?" + str(sortie_number) + "_WindSpeed?TBD_WindDirection?TBD_UVindex?TBD_PixelSize?500" prints b'ASCII\x00\x00\x00Heading_Sortie_WindSpeed_WindDirection_UVindex_PixelSize' piexif.helper.UserComment.dump(comment_string,encoding='ascii') exif_dict["Exif"][piexif.ExifIFD.UserComment] = user_comment exif_bytes = piexif.dump(exif_dict) _UnboundLocalError: local variable 'new_value' referenced before assignment (dump.py, line 337 _dict_to_bytes)
Hello I try to set my FocalLength exif parameter using
`def setImageMeta(image_path, make = u"Basler", model = u"acA2440-35um", focal_length = 4, sensor_width = 8.4, max_image_circle = "2/3\""): o = io.BytesIO() thumb_im = Image.open(image_path) width, height = thumb_im.size width = int(width *0.5) height = int(height * 0.5) thumb_im.thumbnail((width,height), Image.ANTIALIAS) thumb_im.save(o, "jpeg") thumbnail = o.getvalue()
zeroth_ifd = {piexif.ImageIFD.Make: u"Basler", piexif.ImageIFD.Software: u"Inveox" } exif_ifd = { #piexif.ExifIFD.LensMake: "LensMake", piexif.ExifIFD.FocalLength: 8/1, } gps_ifd = { } first_ifd = {piexif.ImageIFD.Make: u"Basler", piexif.ImageIFD.Software: u"Inveox" } exif_dict = {"0th":zeroth_ifd, "Exif":exif_ifd, "GPS":gps_ifd, "1st":first_ifd, "thumbnail":thumbnail} exif_bytes = piexif.dump(exif_dict) piexif.insert(exif_bytes, "Image_Rot10.jpg") im = Image.open("Image_Rot10.jpg") im.thumbnail((100, 100), Image.ANTIALIAS) im.save("out.jpg", exif=exif_bytes)
setImageMeta("Image_Rot10.jpg")`
How ever I get an error that 2
Traceback (most recent call last): File "C:\Users\eclipse-workspace\MetaData.py", line 70, in setImageMeta("Image_Rot10.jpg") File "C:\Users\eclipse-workspace\MetaData.py", line 65, in setImageMeta Inveox 2 (38000.0,) 5 exif_bytes = piexif.dump(exif_dict) File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\piexif_dump.py", line 68, in dump exif_set = _dict_to_bytes(exif_ifd, "Exif", zeroth_length) File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\piexif_dump.py", line 338, in _dict_to_bytes offset) File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\piexif_dump.py", line 248, in _value_to_bytes
four_bytes_over = new_value
UnboundLocalError: local variable 'new_value' referenced before assignment
What am I doing wrong here? I have tried strings ratios and so on.......
Did you solve problem? I have absolutly the same problem with focal length
I could set a focal length with the following code:
exif_dict = piexif.load(image_file_path)
exif_dict['Exif'][piexif.ExifIFD.FocalLength] = (3,1)
The issue that I have is,that I can only input integers, not floats.
Hello I try to set my FocalLength exif parameter using
setImageMeta("Image_Rot10.jpg")`
How ever I get an error that 2
UnboundLocalError: local variable 'new_value' referenced before assignment
What am I doing wrong here? I have tried strings ratios and so on.......