Reputation: 595
I am looking for a script that would open a given number of images with different aspect ratios and layout them all in a single document like the flickr gallery. Something as seen in this page: http://martin-oehm.de/data/layout.html
Is there any script/plugin out there that can do this? The purpose is just to create a reference file with all the images instead of having several images floating around.
Thank you
Upvotes: 1
Views: 1001
Reputation: 208003
The fact that you have had no answers in 10 weeks should tell you that Photoshop is maybe not the best/easiest place to do this.... so, I made the following script that does it pretty well outside of Photoshop.
It assumes you have OSX or Linux to run a bash
script and it uses ImageMagick
to actually do the image processing.
#!/bin/bash
################################################################################
# layout
# Mark Setchell
#
# Layout all images in current directory onto contact sheet. Algorithm is crude
# but fairly effective as follows:
#
# Create temporary workspace
# Resize all images to standard HEIGHT into workspace saving names & new widths
# row=0
# Repeat till there are no images
# Repeat till row is full
# Append widest image that will fit to this row
# End repeat
# Append this row to output contact sheet
# row++
# End repeat
################################################################################
WORKSPACE=layout-$$.d
HEIGHT=300
WIDTH=2000
PAD=50
shopt -s nullglob
shopt -s nocaseglob
# Declare our arrays
declare -a names
declare -a width
declare -a indices
################################################################################
# Returns the number of images remaining still to be laid out
################################################################################
NumRemaining(){
local result=0
local z
for ((z=0;z<${#width[@]};z++)) do
if [ ${width[z]} -gt 0 ]; then
((result++))
fi
done
echo $result
}
################################################################################
# Returns index of widest image that fits in specified width
################################################################################
BestFitting(){
local limit=$1
local index=-1
local widest=0
local z
local t
for ((z=0;z<${#width[@]};z++)) do
t=${width[z]}
if [[ $t -gt 0 && $t -le $limit && $t -gt $widest ]]; then
widest=$t
index=$z
fi
done
echo $index
}
mkdir $WORKSPACE 2> /dev/null
n=0
for f in *.jpg *.png *.gif *.psd; do
# Save name
names[n]=$f
# Extract file extension and basic name, because we want to add "[0]" to end of PSD files
ext="${f##*.}"
base="${f%.*}"
echo $ext | tr "[A-Z]" "[a-z]" | grep -q "psd$"
if [ $? -eq 0 ]; then
convert "$f[0]" -resize x${HEIGHT} $WORKSPACE/${n}.jpg
else
convert "$f" -resize x${HEIGHT} $WORKSPACE/${n}.jpg
fi
# Get width of the resized file and save
width[n]=$(identify -format "%w" $WORKSPACE/${n}.jpg)
echo DEBUG: Index: $n is file: $f thumbnailed to width: ${width[n]}
((n++))
done
echo DEBUG: All images added
echo
cd "$WORKSPACE"
row=0
while [ $(NumRemaining) -gt 0 ]; do
echo DEBUG: Processing row $row, images left $(NumRemaining)
remaining=$WIDTH # new row, we have the full width to play with
cumwidth=0 # cumulative width of images in this row
i=0 # clear array of image indices in this row
while [ $remaining -gt 0 ]; do
best=$(BestFitting $remaining)
if [ $best -lt 0 ]; then break; fi
indices[i]=$best # add this image's index to the indices of images in this row
w=${width[best]}
((cumwidth=cumwidth+w))
((remaining=WIDTH-cumwidth-i*PAD)) # decrease remaining space on this line
width[best]=-1 # effectively remove image from list
((i++))
echo DEBUG: Adding index: $best, width=$w, cumwidth=$cumwidth, remaining=$remaining
done
if [ $i -lt 1 ]; then break; fi # break if no images in this row
PADWIDTH=$PAD
if [ $i -gt 1 ]; then ((PADWIDTH=(WIDTH-cumwidth)/(i-1))); fi
echo $(NumRemaining)
echo $i
if [ $(NumRemaining) -eq 0 ]; then PADWIDTH=$PAD; fi # don't stretch last row
echo DEBUG: Padding between images: $PADWIDTH
ROWFILE="row-${row}.png"
THIS="${indices[0]}.jpg"
# Start row with left pad
convert -size ${PAD}x${HEIGHT}! xc:white $ROWFILE
for ((z=0;z<$i;z++)); do
if [ $z -gt 0 ]; then
# Add pad to right before appending image
convert $ROWFILE -size ${PADWIDTH}x${HEIGHT}! xc:white +append $ROWFILE
fi
THIS="${indices[z]}.jpg"
convert $ROWFILE $THIS +append $ROWFILE
done
# End row with right pad
convert $ROWFILE -size ${PAD}x${HEIGHT}! xc:white +append $ROWFILE
((row++))
echo DEBUG: End of row
echo
done
# Having generated all rows, append them all together one below the next
((tmp=WIDTH+2*PAD))
convert -size ${tmp}x${PAD} xc:white result.png
for r in row*.png; do
convert result.png $r -size ${tmp}x${PAD}! xc:white -append result.png
done
open result.png
Depending on the files in your input directory (obviously), it produces output like this:
with debug information in your Terminal window as it goes like this:
DEBUG: Index: 0 is file: 1.png thumbnailed to width: 800
DEBUG: Index: 1 is file: 10.png thumbnailed to width: 236
DEBUG: Index: 2 is file: 11.png thumbnailed to width: 236
DEBUG: Index: 3 is file: 12.png thumbnailed to width: 360
DEBUG: Index: 4 is file: 2.png thumbnailed to width: 480
DEBUG: Index: 5 is file: 3.png thumbnailed to width: 240
DEBUG: Index: 6 is file: 4.png thumbnailed to width: 218
DEBUG: Index: 7 is file: 5.png thumbnailed to width: 375
DEBUG: Index: 8 is file: 6.png thumbnailed to width: 1125
DEBUG: Index: 9 is file: 7.png thumbnailed to width: 1226
DEBUG: Index: 10 is file: 8.png thumbnailed to width: 450
DEBUG: Index: 11 is file: 9.png thumbnailed to width: 300
DEBUG: Index: 12 is file: a.png thumbnailed to width: 400
DEBUG: All images added
DEBUG: Processing row 0, images left 13
DEBUG: Adding index: 9, width=1226, cumwidth=1226, remaining=774
DEBUG: Adding index: 4, width=480, cumwidth=1706, remaining=244
DEBUG: Adding index: 5, width=240, cumwidth=1946, remaining=-46
DEBUG: Padding between images: 27
DEBUG: End of row
DEBUG: Processing row 1, images left 10
DEBUG: Adding index: 8, width=1125, cumwidth=1125, remaining=875
DEBUG: Adding index: 0, width=800, cumwidth=1925, remaining=25
DEBUG: Padding between images: 75
DEBUG: End of row
DEBUG: Processing row 2, images left 8
DEBUG: Adding index: 10, width=450, cumwidth=450, remaining=1550
DEBUG: Adding index: 12, width=400, cumwidth=850, remaining=1100
DEBUG: Adding index: 7, width=375, cumwidth=1225, remaining=675
DEBUG: Adding index: 3, width=360, cumwidth=1585, remaining=265
DEBUG: Adding index: 1, width=236, cumwidth=1821, remaining=-21
DEBUG: Padding between images: 44
DEBUG: End of row
DEBUG: Processing row 3, images left 3
DEBUG: Adding index: 11, width=300, cumwidth=300, remaining=1700
DEBUG: Adding index: 2, width=236, cumwidth=536, remaining=1414
DEBUG: Adding index: 6, width=218, cumwidth=754, remaining=1146
DEBUG: Padding between images: 623
DEBUG: End of row
Upon reflection, the output could maybe be improved by reversing odd-numbered rows so that the largest image on each line is on the left one time and on the right the next time - it is a simple change but I don't want to over-complicate the code. Basically, you would reverse the order of the array indices[]
every second time you fall out of the row-assembling loop.
Here are some maybe useful links:
I presume Photoshop's built-in File
->Automate
->Contact Sheet II
is inadequate for your purposes...
Upvotes: 3