0

imagemagickで写真に年を入れたい。約4000枚の写真があります。-compose パラメータを使用して imagemagick で実行しようとしています。

ロゴは 200x67 ピクセルです。

ロゴ

しかし、すべての写真は同じサイズではありません。各画像に年の比例サイズを追加するにはどうすればよいですか?

サンプル画像

サンプル画像

imagemagick はまだ試していませんが、Photoshop で 2 つの異なる写真にロゴを配置しました。それともimagemagickがこれを処理しますか? または、定義されたフォントサイズで各画像にテキストを配置できますか? または、すべての画像を 1 つのサイズに変換したほうがよいでしょうか? その場合、imagemagick は最小の画像を教えてくれますか?

4

2 に答える 2

0

スクリプトを作成しましたhttp://pastebin.com/HdBMx2Zm XP マシン (ACDSee) と Windows 7 (Windows 統合イメージ ビューアー) で見栄えがします。一部の写真では、年が少し大胆になっていますが、問題ありません。

#!/bin/bash
#
# 
# 
# find /media/sf_test/meklee/ -type f -iname "*.jpg" -exec /root/imagick_script.sh "{}" \;
#
# depends on jhead and imagemagick
# if call find from another file, then is possible to count all pictures, place count on file and in imagick_script.sh
# decrase that amount by 1. 
# 
# in script some directory names is in Latvian :)
#

backgroundimage=$1
bgp=/media/sf_test/


if [ -f "${bgp}stop" ]
then
    echo -ne "*"
    exit 0
fi

if [ ! -d "${bgp}2019" ]
then
    mkdir -p "${bgp}2019"
fi

# "%[fx:w] %[fx:h] %[exif:DateTime]" (use this if images has no exif data)
#dim=`identify -format "%[fx:.15*w] %[fx:.15*h] %[exif:orientation] %[exif:DateTime]" "$backgroundimage"`

# be careful with auto-orient
# see this: http://www.imagemagick.org/script/command-line-options.php?#auto-orient
#orient=`echo $dim | awk '{print $3}'`
#if [ "$orient" != "1" ]
#then
#orient image (rewrite original)
#    convert -auto-orient "$1" "$1"
#re-read image data
#    dim=`identify -format "%[fx:.15*w] %[fx:.15*h] %[exif:orientation] %[exif:DateTime]" "$backgroundimage"`
#fi


# jhead is much faster...


#ww=`echo $dim | awk '{print $1}'`
#hh=`echo $dim | awk '{print $2}'`
#ww=`printf "%.0f\n" "${ww}"`
#hh=`printf "%.0f\n" "${hh}"`
ww=`jhead "$1" | grep 'Resolution' | awk '{print $3}'`
hh=`jhead "$1" | grep 'Resolution' | awk '{print $5}'`
ww=`echo "$ww * .15" | bc -l  | xargs printf "%1.0f"`
hh=`echo "$hh * .15" | bc -l  | xargs printf "%1.0f"`


if [ "$hh" -gt "$ww" ]
then
    let ww=$ww*2
fi

#year=`echo $dim | awk '{print substr($4,1,4)}'`
# works only if exif is avaiable..
year=`jhead "$1" | grep 'File date' | awk '{print substr($4,1,4)}'`

# i have images takin in range from 2004 to 2012, so if some exim data is removed, use year 2019..
case "$year" in
'2004')
    #
;;
'2005')
    #
;;
'2006')
    #
;;
'2007')
    #
;;
'2008')
    #
;;
'2009')
    #
;;
'2010')
    #
;;
'2011')
    #
;;
'2012')
    #
;;
*)
    year=2019
    mv "$1" "${bgp}2019"
    echo -ne "!"
    exit 0
;;
esac



if [ ! -f ${bgp}${year}.png ];
then
    convert -gravity southeast -size 300x130 xc:transparent -font Courier-bold -pointsize 125 -fill red -draw "text 0,0 '${year}'" ${bgp}output.png
    composite  ${bgp}output.png ${bgp}fons.png ${bgp}${year}.png
    #echo "${year}.png not found, create one ..";
fi

Watermark=${bgp}${year}.png


Fname="${backgroundimage##*/}"
Fdir="${backgroundimage:0:${#backgroundimage} - ${#Fname}}"
#echo "${Fdir}new_$Fname"
#echo "${ww}x$hh $1"
if [ ! -d "/media/sf_test/resize/$year/" ] 
then
    mkdir "/media/sf_test/resize/$year/"
fi

if [ ! -d "/media/sf_test/apstradatie/$year/" ]
then
    mkdir "/media/sf_test/apstradatie/$year/"
fi

if [ ! -f "/media/sf_test/resize/$year/$Fname" ]
then
    composite -gravity southeast \( $Watermark -resize ${ww}x${hh} \) "$backgroundimage" "/media/sf_test/resize/$year/$Fname"
fi
mv "$1" "/media/sf_test/apstradatie/$year"
#"${Fdir}neew_$Fname"

echo -ne "."
于 2013-01-17T13:24:05.417 に答える
0

次のことをお勧めします。

後で縮小できるように、大きいサイズのロゴを作成します。

次に、すべての画像をループします。

  1. 画像の画像サイズを取得します。

    $size_array = getimagesize ( $image_src );

    $width = $size_array[0];

    $height = $size_array[1];

  2. 画像サイズに応じて、ロゴのコピーを縮小します

  3. 画像の上にロゴを合成

于 2013-01-16T10:36:09.827 に答える