Jump to content
  • Announcements

    • Allan

      Forum Rules   04/13/2018

      Hello folks! As some things are being fixed, we'll keep you updated. Per hour the Forum Rules don't have a dedicated "Tab", so here is the place that we have our Rules back. New Users Lounge > [READ] - InsanelyMac Forum Rules - The InsanelyMac Staff Team. 

Combine Text File and Image

3 posts in this topic

Recommended Posts

I am needing a script that will take a text file that has an image URL and 2 lines of text and create one image out of the URL image with the 2 lines of text underneath it all in one image.


So the text file would contain:



Text Line 1

Text Line 2




I need the final image to look like the file I have attached.


Share this post

Link to post
Share on other sites

You could do this using Python, but first you'll need to install the pil module.


Below is a bash script to install the module and libs that you need (you'll need Xcode/Xcode Command Line Tools installed):



echo "Select MacOS Version:"
echo "[1] Lion"
echo "[2] Snow Leopard"
read selection

case $selection in
*) Echo "No Selection Made"
exit 0
curl -O $OPTION

sudo installer -pkg libjpeg-8d-0.pkg -target /
sudo easy_install pip
sudo pip install pil
sudo pip install pillow


Then you could try something like this in Python:


#!/usr/bin/env python
import os,sys,urllib2,Image,ImageDraw,ImageFont
fname = raw_input("Enter Filename: ")
txt = open(fname).readlines()
asset,text1,text2,blank = txt
savedFilename = os.path.basename(asset).strip()
imgfile = urllib2.urlopen(asset)
savedfile = open(savedFilename,'wb')

im = Image.open(savedFilename)
font = ImageFont.truetype('/Library/Fonts/Verdana Bold.ttf',14)
box = im.getbbox()
im2=im.crop((box[0], box[1], box[2], box[3]+50))
draw.text((box[1]+10,box[3]+10), text1.strip(),font=font)
draw.text((box[1]+10,box[3]+30), text2.strip(), font=font)


The Python script reads a single text file that has the 3 entries you listed, terminated with a blank line.





Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.