0

I am very new to Python and learning more every day :-). I have been trying to figure out this problem for some time now, but realize that need some help.

I am downloading images from a webpage and in the process I am trying to add Exif information to the image, so I can upload images to a Wordpress site with Exif data. Ideal I would like to have the following Exif data added to the image:

  • Wordpress Title
  • Wordpress Alt-text
  • Wordpress Caption
  • Wordpress Keyword

Is there any way to add this EXIF data when I download images?

I am downloading images with this code:


def collection_():  
    dict_collection = {}
    
    for row in range(start_row, end_row):
      key = ws.cell(row, address_column).value
      value = ws.cell(row, picture_pic).value
      dict_collection[key] = value
      if picture_pic == 15:
        urllib.request.urlretrieve(value, path_collection + key + '.jpg')
        print('Saved: ' + key + '.jpg')
      else:
        urllib.request.urlretrieve(value, address_folder + key + '_' + str(picture_pic) + .jpg')
        print('Saved: ' + key + '_' + str(picture_pic) + '.jpg')

This is based on an Excel sheet, where all the information about a given image is listed. The download works very well :-)

The below code works on a single image, where the name of the image is defined. What I would like to do, is to add this code to "def collection()". The Exif data listed in the code works when the data is fixed, but it's missing some of the information from my "wish list".

o = io.BytesIO()
    thumb_im = Image.open('???????.jpg')
    thumb_im.save(o, "jpeg")
    thumbnail = o.getvalue()


    zeroth_ifd = {piexif.ImageIFD.ImageDescription: u'column 27 from Excel',
                  piexif.ImageIFD.Artist: u'fixed value',
                  }

    exif_ifd = {piexif.ExifIFD.UserComment: 'Column 28 from Excel'.encode('utf-8'),


                }

    exif_dict = {"0th":zeroth_ifd, "Exif":exif_ifd,}
    exif_bytes = piexif.dump(exif_dict)
    im = Image.open(???????'.jpg')
    im.save("????????.jpg", exif=exif_bytes)`

All help is greatly appriciated! I just don't have the knowledge to get this to work.

0 Answers0