Make Featured Images Just Like The Renegade Coder

Make Featured Images Just Like The Renegade Coder Featured Image

Last Updated on

Recently, @hmajid2301 made a pull request to my image-titler repo to turn that Python script into a pip package. Naturally, I wanted to take some time to give the project a bit more love. Let’s learn how to make featured images just like The Renegade Coder.

Table of Contents

What is image-titler?

Awhile back, my wife and I worked together to create a template I could use to create featured images for my website. Eventually, we settled on the double red bar template that you can see in practice at the top of this article.

To make use of the template, I used to have to do the following:

  1. Download a picture
  2. Upload picture to an online image editor
  3. Apply the template
  4. Replace the template text
  5. Resize the red bars
  6. Fiddle with positioning until happy

Of course, I find repetitive tasks tiresome, so I had to find a way to automate the above process. As a result, I turned to Python to see if I could make a small script to apply the template automatically. The result is something I called image-titler.

How Does image-titler Work?

The image-titler script works by splitting the image title by the space nearest the midpoint then mapping the two substrings on red blocks and positioning those blocks as you see them. For example, the title for this article is “Make Featured Images Just Like The Renegade Coder.” Splitting by the closest space to the midpoint yields “Make Featured Images Just” and “Like The Renegade Coder”:

>>> from image_titler import trc_image_titler
>>> trc_image_titler.split_string_by_nearest_middle_space("Make Featured Images Just Like The Renegade Coder")
('Make Featured Images Just', 'Like The Renegade Coder')

In total, there are four 4 functions at play here: main, split_string_by_nearest_middle_space, draw_text, and save_copy. As usual, the main function reads in the options and runs the image titling process based on those options. The other three methods serve as the business logic for the entire script.

Amazingly, the entire script is 135 lines of code which includes documentation, imports, and constants. In other words, there are loads of opportunities to make this script your own. Why not swing by the repo and make pull request?

How Can I Use image-titler?

Since image-titler is now a pip package, using it is pretty simple:

pip install image-titler
image_titler

From there, the program should launch a file input window which asks for your image. Once you select your file, it will attempt to parse the file name and generate the title. In particular, the script expects file names separated by hyphens. For example, the featured image for this article has the following file name: make-featured-images-just-like-the-renegade-coder.jpg.

If you’d like a little more control, there are three options:

  • -o: sets the output path
  • -t: sets the title to be placed on the image
  • -p: sets the path of the input file

For example, the following code snippet runs image-titler with a fixed title:

image_titler -t "Make Featured Images Just Like The Renegade Coder"

From there, you’ll be prompted to select an image file, and the result will be dumped to the working directory.

How Can I Help image-titler?

As mentioned before, I’d love for other folks to see if they can find a use for the script. Currently, it’s essentially hardcoded to my style, but I’m sure you could extend it to your needs. A fun start might be to make the bar color configurable through optional parameters. In addition, I’d like to be able to scale images down, so cropping works correctly.

If this project sounds interesting at all, I recommend taking a look at the source code. If I know anything about the internet and the coding community, it’s that I’m guaranteed to find someone who won’t like something about my code. So, why not take a crack at it?

While you’re here, you may also be interested in helping The Renegade Coder community expand the Sample Programs repo. It’s a collection of code snippets in as many languages as possible. Currently, we’d love to have some help with documentation end of things. A lot of the code needs documented.

At any rate, thanks for swinging by! If you know anyone who would be interested in helping out, share this article with them. I’d appreciate the support!

Advertisements

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.