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?
put a green boarder and text around multiple pictures
put a green boarder and text around multiple pictures
|
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'.
Jul-05-2022, 09:16 AM
(Jul-05-2022, 08:52 AM)DPaul Wrote: The answer is yes. 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
Jul-05-2022, 09:31 AM
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'.
Jul-05-2022, 09:47 AM
Zero python experience but will give it a go. Thanks.
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() ![]() 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. |
|
Users browsing this thread: 1 Guest(s)