Automatically add width and height attributes to image tag

Some time ago I needed to add height and width attributes to all images on this blog. So I wrote a python script, here is the main idea:

  • Iterate over all blog posts.
  • Find all img tags in each post.
  • Extract the content of the src attribute.
  • Open the image and extract its size.
  • Write image size in the img attribues width and height.

Continue reading on my blog

Like what you read? Give The Programmer’s Chest a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.