Photoshop脚本:布局图像,如flickr

时间:2015-03-17 13:10:01

标签: photoshop photoshop-script

我正在寻找一个脚本,可以打开具有不同宽高比的给定数量的图像,并将它们全部放在单个文档中,如flickr库。如本页所示:http://martin-oehm.de/data/layout.html

有没有可以执行此操作的脚本/插件?目的只是创建一个包含所有图像的参考文件,而不是浮动几个图像。

谢谢

1 个答案:

答案 0 :(得分:2)

你在10周内没有答案的事实应该告诉你Photoshop可能不是最好/最容易做到这一点的地方....所以,我制作了以下脚本,它在Photoshop之外做得非常好。

它假设你有OSX或Linux来运行bash脚本,它使用ImageMagick来实际进行图像处理。

#!/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

根据输入目录中的文件(显然),它会产生如下输出:

enter image description here

在终端窗口中显示调试信息,如下所示:

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

在反射时,可以通过反转奇数行来改善输出,使得每行上的最大图像一次在左边,而在下一次右边 - 这是一个简单的改变,但我不是想要使代码过于复杂。基本上,每次第二次退出行装配循环时,都会颠倒数组indices[]的顺序。

以下是一些可能有用的链接:

Google+ algorithm

flickr algorithm in jQuery

我认为Photoshop的内置File - &gt; Automate - &gt; Contact Sheet II不适合您的目的......