Python Forum
put a green boarder and text around multiple pictures
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
put a green boarder and text around multiple pictures
#1
Photo 
I have 90 pictures that I need to add a green boarder and text around (see image attached). I then need these pictures to be saved into a folder where their dimensions are 400 x 300 pixels and then saved again into a folder where their dimensions are 120 x 90 pixels. Is there a way to do this using python?
       
Reply
#2
The answer is yes.
It is not diffficult, but requires some fidgeting, depending on the starting conditions.
1) Are all the pictures the same size to start with ?
2) How big do you want the border to be (in pixels) ?
All you need is:
from PIL import Image
Determine height and with, resize (with respect of proportions)
For the border, i would make a template picture (green) slightly bigger than 400x300,
and put the pictures in the middle and the text at the bottom. There are other posiibilities.
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#3
(Jul-05-2022, 08:52 AM)DPaul Wrote: The answer is yes.
It is not diffficult, but requires some fidgeting, depending on the starting conditions.
1) Are all the pictures the same size to start with ?
2) How big do you want the border to be (in pixels) ?
All you need is:
from PIL import Image
Determine height and with, resize (with respect of proportions)
For the border, i would make a template picture (green) slightly bigger than 400x300,
and put the pictures in the middle and the text at the bottom. There are other posiibilities.
Paul

Hi Paul, thanks for the reply.
Yes all the pictures are the same size to start with and the green boarder needs to be 10 pixels in thickness
Reply
#4
I do not know your level of Python experience ,
but if what i'm suggesting is news to you, i would recommend using
Gimp, PSelements, etc. It will save hours.
I would.
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#5
Zero python experience but will give it a go. Thanks.
Reply
#6
Border is quite easy example.
# pip install pillow
from PIL import Image, ImageOps

img = Image.open("task.jpg")
# border color
color = "green"
# top, right, bottom, left
border = (20, 20, 20, 20)
new_img = ImageOps.expand(img, border=border, fill=color)
# save new image
new_img.save("image_result.jpg")
# show new bordered image in preview
new_img.show()
[Image: Kg2Ey9.jpg]

For adding text look at Pillow ImageFont Module.
Read many images in a loop is a stander task in Python,eg i would suggest pathlib for this.
Maybe easier to in a two process step one add green border,step two add text.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Find a shift between 2 pictures TazFleck 0 1,142 Jan-18-2023, 09:56 PM
Last Post: TazFleck
  Replace String in multiple text-files [SOLVED] AlphaInc 5 8,096 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt
  Open and read multiple text files and match words kozaizsvemira 3 6,733 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  Reading Multiple text Files in pyhton Fatim 1 1,914 Jun-25-2021, 01:37 PM
Last Post: deanhystad
  Random pictures from a file aliwien 2 4,330 Apr-23-2021, 06:00 PM
Last Post: snippsat
Question How to extract multiple text from a string? chatguy 2 2,358 Feb-28-2021, 07:39 AM
Last Post: bowlofred
  Help with taking pictures on raspberry pi octavia 1 1,692 Feb-07-2020, 04:54 PM
Last Post: Larz60+
  client-server pictures mcgrim 4 2,967 Oct-25-2019, 09:53 PM
Last Post: micseydel
  Using a file to send multiple contacts Text via GSM sim 01001B 0 2,013 Sep-14-2019, 05:41 PM
Last Post: 01001B
  Open Pictures with Python MaxouRuEnIpTF34 1 3,036 Apr-22-2018, 07:48 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020