Yesterday I decided to make a program for creation a collage from images.
I've selected the next important input parameters: images list, output resulting collage image, width of resulting collage and the value of images' initial height (this value is approximate and will change, to fit the line of images in given width).
I've chosen the next algorithm:
1) Try to add images (resized to initial height) one by one to the first line:
And when the sum of their widths will go beyond the width value, start the next line.
2) After all images were added to the line, need to fit their size to width value. Here the height of images in the line will be changed from initial height.
3) Resize images to fit the width in all lines.
4) If one of the lines will contain only one image - need to repeat all steps from the beginning again, reducing the initial height value, to compact lines and to find a place for mentioned "alone" image.
I've also added shuffle of images, to get different collages each time.
The result of the program is the next:
Source code for collage maker is available on my github: https://github.com/delimitry/collage_maker
It's written in Python and uses PIL (Python Imaging Library).
There is an error if the height of the image is less than the provided height(init_height) collages will have a black patch, to resolve this I have resized the image with height = init_height and proportional width.
ReplyDeleteI have used this snippet:
baseheight = init_height
hpercent = (baseheight / float(img.size[1]))
wsize = int((float(img.size[0]) * float(hpercent)))
img = img.resize((wsize, baseheight), PIL.Image.ANTIALIAS)
Exactly in which part of the code, did you make these changes?
DeleteI am facing similar issues.
Thank you.
Great for porn sites, thank you
ReplyDeletebruh
DeleteThanks for the work. I tried with example images and it works like said.
ReplyDeleteIt's also interesting for reading and learning code.
Thanks again.
Hi thanks for source code. I want to ask a question please. How can i make collage verticaly?
ReplyDeleteWhy is it so difficult? where is exe file and interface? What I am supposed to do with this code? I dont understand anything!
ReplyDeleteit is not difficult if you take the time to learn a little python, a common programming language. There is no exe, because it is not a windows executable. The source code is at the link above, just before the comments section. It has the command line syntax.
DeleteI am new to GitHub and I have lots to say
DeleteI DONT GIVE A FUCK ABOUT THE FUCKING CODE! i just want to download this stupid fucking application and use it https://github.com/delimitry/collage_maker
WHY IS THERE CODE??? MAKE A FUCKING .EXE FILE AND GIVE IT TO ME. these dumbfucks think that everyone is a developer and understands code. well i am not and i don't understand it. I only know to download and install applications. SO WHY THE FUCK IS THERE CODE? make an EXE file and give it to me. STUPID FUCKING SMELLY NERDS
;) - https://www.reddit.com/r/ProgrammerHumor/comments/1awnebi/sherlockmaintainer/
> I DONT GIVE A FUCK ABOUT THE FUCKING CODE!
Delete>WHY IS THERE CODE??? MAKE A FUCKING .EXE FILE AND GIVE IT TO ME.
This script/program wasn't made for you then.
There's plenty of other solutions out there for people that want to perform a single edit using a UI (UI is the clickable buttons you are expecting).
Thank you!
Very interesting, good job and thanks for sharing such a good blog. Your article is so convincing that I never stop myself to say something about it. You're doing a great job. Keep it up.
ReplyDeleteblur
It would be great if the order was alphabetical, left to right, top down.
ReplyDeleteThat's an easy fix, just sort the images list before creating the collage. Under line 100 add images.sort()
DeleteThanks for making this tool. I find it very useful.
ReplyDeleteI personally LOVE that it is in console format vs what was said before allowing me to use it with any of my existing or new scripts versus having a UI that would make this difficult as I'd have to use an automation program at that point to use the UI.
To the .exe guy: If you can't use this tool; it isn't made for you.
Please set up some kind of obvious donation page for people that like to drop something for useful open source software we encounter.
Thank you!