【问题标题】:imagemagick comosite proportion to image sizeimagemagick comosite 与图像大小的比例
【发布时间】:2013-01-16 10:13:21
【问题描述】:

我想用 imagemagick 把年份放在图片上。我有大约4000张照片。我尝试使用 -compose 参数使用 imagemagick 来做到这一点。

徽标为 200x67 像素。

但是所有图片的大小都不一样。我如何在每张图片上添加年份的比例大小?

示例图片

我还没有尝试 imagemagick,但我用 Photoshop 将徽标放在了两张不同的图片上。 或者 imagemagick 处理这个?或者我可以用定义的字体大小在每个图像上放置文本?或者更好地将所有图像转换为一种尺寸?如果是这样,imagemagick 可以告诉我最小的图片吗?

【问题讨论】:

  • 我做了一些脚本pastebin.com/ZDeZagmD,在我的屏幕上看起来不错。我也在另一台笔记本电脑上尝试过。

标签: imagemagick imagemagick-convert


【解决方案1】:

我建议您执行以下操作:

创建更大尺寸的徽标,以便您以后可以将其缩小

然后循环遍历所有图像:

  1. 获取图片的图片大小:

    $size_array = getimagesize ($image_src);

    $width = $size_array[0];

    $height = $size_array[1];

  2. 根据图像大小,缩小徽标副本

  3. 在图片上撰写徽标

【讨论】:

    【解决方案2】:

    我制作了脚本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 "."
    

    【讨论】:

      猜你喜欢
      • 2011-09-17
      • 2017-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-14
      • 1970-01-01
      • 2011-09-20
      • 2011-07-15
      相关资源
      最近更新 更多