#!/bin/bash #----------------------------------------------------------------------------- function usage_one_line { uol_arg=$1 while [ ${#uol_arg} -lt 77 ] do uol_arg="$uol_arg " done uol_arg="$uol_arg\\" echo "$uol_arg" } # usage_one_line #----------------------------------------------------------------------------- function usage { usage_one_line "usage: $0 infile outfile (or - for outfile if interactive)" 1>&2 usage_one_line " [ rotate 0|90|180|270 ]" 1>&2 usage_one_line " [ rotate2 interpolate0|1 radians ]" 1>&2 usage_one_line " [ text cx cy x y size \"r g b\" bold|medium \"hi ho\" ]" 1>&2 usage_one_line " [ flaretext cx cy x y size \"r g b\" \"r g b\" bold|medium \"hi ho\" ]" 1>&2 usage_one_line " [ size width height ]" 1>&2 usage_one_line " [ crop width height x-origin y-origin ]" 1>&2 usage_one_line " [ hls affected-hues hue-offset lightness saturation ]" 1>&2 usage_one_line " [ cbal mode0|1|2 preserve-lum0|1 cyan-red magenta-green yellow-blue ]" 1>&2 usage_one_line " [ brightcont brightness contrast ]" 1>&2 usage_one_line " [ perspective ulx uly urx ury llx lly lrx lry direction interpolation recursion clip ]" 1>&2 echo " [ comment \"This is a comment.\"]" 1>&2 echo "If cx cy are 0.0 0.0 then x y is for the top left corner of the text box." 1>&2 echo "If cx cy are 1.0 1.0 then x y is for the bottom right corner of the text box." 1>&2 echo "On hls, set affected-hues to 0. Colors range from -100 to 100." 1>&2 echo "On cbal, use all modes, preserve-lum 1. Colors range from -100 to 100." 1>&2 echo "On brightcont, brightness and contrast range from -127 to 127." 1>&2 echo "On direction, 0 is transform-forward; 1 is transform-backward." 1>&2 echo "On interpolation, 0 is none, 1 is linear, 2 is cubic, 3 is lanczos." 1>&2 echo "On recursion, make it at least 1; 3 is nice." 1>&2 echo "On clip, 0 is adjust, 1 is clip, 2 is crop, 3 is crop-with-aspect." 1>&2 exit 1 } # usage #----------------------------------------------------------------------------- function check_number { if [ ${#1} = 0 ] then echo width or height is missing 1>&2 usage fi cn_nondigits=x`echo "$1"|sed -e 's/[0-9]//g'` if [ ${#cn_nondigits} -ne 1 ] then echo width or height contains non-numerical data usage fi cn_nonzero=x`echo "$1"|sed -e 's/0//g'` if [ ${#cn_nonzero} -eq 1 ] then echo width or height is zero, and that is not allowed usage fi } # check_number #----------------------------------------------------------------------------- #rm -rf ~/.gimp*/*swap* if [ $# -lt 2 ] then usage fi in_file=$1 shift out_file=$1 shift doing_something=n need_drawable=y x=' ( let*' x=$x' (' x=$x' ( in-file "'$in_file'" )' x=$x' ( out-file "'$out_file'" )' x=$x' ( border "" )' x=$x' ( comment "" )' x=$x' ( feather "" )' x=$x' ( flare-color "" )' x=$x' ( font "" )' x=$x' ( foundry "" )' x=$x' ( grow "" )' x=$x' ( size "" )' x=$x' ( slant "" )' x=$x' ( text "" )' x=$x' ( text-color "" )' x=$x' ( text-height "" )' x=$x' ( text-layer "" )' x=$x' ( text-tl-x "" )' x=$x' ( text-tl-y "" )' x=$x' ( text-width "" )' x=$x' ( the-display "" )' x=$x' ( the-drawable "" )' x=$x' ( the-image "" )' x=$x' ( weight "" )' x=$x' ( x-coefficient "" )' x=$x' ( x-position "" )' x=$x' ( y-coefficient "" )' x=$x' ( y-position "" )' x=$x' )' x=$x' ( set! comment "your ad here" )' x=$x' ( set! the-image ( car ( file-jpeg-load 1 in-file in-file )))' while [ $# -gt 0 ] do if [ "x$need_drawable" = "xy" ] then x=$x' ( set! the-drawable ( car ( gimp-image-active-drawable the-image )))' fi if [ "x$1" = "xrotate" ] then if [ $# -lt 2 ] then usage fi shift if [ "x$1" = "x0" ] then rotate_extent="0" elif [ "x$1" = "x90" ] then rotate_extent="1" elif [ "x$1" = "x180" ] then rotate_extent="2" elif [ "x$1" = "x270" ] then rotate_extent="3" else usage fi shift if [ "$rotate_extent" != "0" ] then doing_something=y x=$x' ( plug-in-rotate 1 the-image the-drawable '$rotate_extent' 1 )' fi elif [ "x$1" = "xrotate2" ] then if [ $# -lt 3 ] then usage fi shift interpolate=$1 shift radians=$1 shift doing_something=y x=$x' ( gimp-rotate the-drawable '$interpolate' '$radians' )' elif [ "x$1" = "xtext" ] then if [ $# -lt 9 ] then usage fi shift x_coefficient=$1 shift y_coefficient=$1 shift x_position=$1 shift y_position=$1 shift text_size=$1 shift text_color=$1 shift weight=$1 shift text_content=$1 shift doing_something=y x=$x' (set! x-coefficient '"$x_coefficient"')' x=$x' (set! y-coefficient '"$y_coefficient"')' x=$x' (set! text "'"$text_content"'")' x=$x' (set! size '"$text_size "' )' x=$x' (set! x-position '"$x_position "' )' x=$x' (set! y-position '"$y_position "' )' x=$x' (set! foundry "adobe" )' # example: "adobe" x=$x' (set! font "courier" )' # example: "courier" x=$x' (set! weight "'"$weight"'" )' # example: "medium" or "bold" x=$x' (set! slant "r" )' # example: "r" for roman or "i" for italic or "o" for oblique x=$x' (set! text-color (list '"$text_color "'))' # --- end of configuration --- x=$x' (set! border 0)' x=$x' (set! text-width (car (gimp-text-get-extents text size PIXELS foundry font weight slant "*" "*" "*" "*")))' x=$x' (set! text-height (cadr (gimp-text-get-extents text size PIXELS foundry font weight slant "*" "*" "*" "*")))' x=$x' (set! text-width (+ text-width border border))' x=$x' (set! text-height (+ text-height border border))' x=$x' (set! text-tl-x (- x-position (* x-coefficient text-width )))' x=$x' (set! text-tl-y (- y-position (* y-coefficient text-height)))' x=$x' (gimp-palette-set-foreground text-color )' x=$x' (set! text-layer ( car ( gimp-text the-image -1 text-tl-x text-tl-y text 0 TRUE size PIXELS foundry font weight slant "*" "*" "*" "*" )))' x=$x' (set! the-drawable ( car ( gimp-image-merge-visible-layers the-image 2)))' x=$x' (gimp-palette-set-foreground ( list 0 0 0 ))' elif [ "x$1" = "xflaretext" ] then if [ $# -lt 9 ] then usage fi shift x_coefficient=$1 shift y_coefficient=$1 shift x_position=$1 shift y_position=$1 shift text_size=$1 shift text_color=$1 shift flare_color=$1 shift weight=$1 shift text_content=$1 shift doing_something=y x=$x' (set! x-coefficient '"$x_coefficient"')' x=$x' (set! y-coefficient '"$y_coefficient"')' x=$x' (set! text "'"$text_content"'")' x=$x' (set! size '"$text_size "' )' x=$x' (set! x-position '"$x_position "' )' x=$x' (set! y-position '"$y_position "' )' x=$x' (set! foundry "adobe" )' # example: "adobe" x=$x' (set! font "courier" )' # example: "courier" x=$x' (set! weight "'"$weight"'" )' # example: "medium" or "bold" x=$x' (set! slant "r" )' # example: "r" for roman or "i" for italic or "o" for oblique x=$x' (set! text-color (list '"$text_color "'))' x=$x' (set! flare-color (list '"$flare_color"'))' # --- end of configuration --- x=$x' (set! border (/ size 4.0))' x=$x' (set! grow (/ size 8.0))' x=$x' (set! feather (/ size 4.0))' x=$x' (set! text-width (car (gimp-text-get-extents text size PIXELS foundry font weight slant "*" "*" "*" "*")))' x=$x' (set! text-height (cadr (gimp-text-get-extents text size PIXELS foundry font weight slant "*" "*" "*" "*")))' x=$x' (set! text-width (+ text-width border border size))' x=$x' (set! text-height (+ text-height border border))' x=$x' (set! text-tl-x (- x-position (* x-coefficient text-width )))' x=$x' (set! text-tl-y (- y-position (* y-coefficient text-height)))' x=$x' (set! text-layer ( car ( gimp-text the-image the-drawable text-tl-x text-tl-y text border TRUE size PIXELS foundry font weight slant "*" "*" "*" "*" )))' x=$x' (gimp-selection-layer-alpha text-layer)' x=$x' (gimp-image-remove-layer the-image text-layer)' x=$x' (gimp-selection-grow the-image grow)' x=$x' (gimp-selection-feather the-image feather)' x=$x' (gimp-palette-set-foreground flare-color)' x=$x' (gimp-edit-fill the-drawable FG-IMAGE-FILL)' x=$x' (gimp-palette-set-foreground text-color)' x=$x' (set! text-layer ( car ( gimp-text the-image -1 text-tl-x text-tl-y text border TRUE size PIXELS foundry font weight slant "*" "*" "*" "*" )))' x=$x' (set! the-drawable ( car (gimp-image-flatten the-image)))' elif [ "x$1" = "xsize" ] then if [ $# -lt 3 ] then usage fi shift x_size=$1 shift y_size=$1 shift doing_something=y x=$x' (gimp-image-scale the-image '"$x_size"' '"$y_size"' )' elif [ "x$1" = "xcrop" ] then if [ $# -lt 5 ] then usage fi shift x_size=$1 shift y_size=$1 shift x_origin=$1 shift y_origin=$1 shift doing_something=y x=$x' (gimp-crop the-image '"$x_size"' '"$y_size"' '"$x_origin"' '"$y_origin"' )' elif [ "x$1" = "xhls" ] then if [ $# -lt 5 ] then usage fi shift affected_hues=$1 shift hue_offset=$1 shift new_lightness=$1 shift new_saturation=$1 shift doing_something=y x=$x' (gimp-hue-saturation the-drawable '"$affected_hues"' '"$hue_offset"' '"$new_lightness"' '"$new_saturation"' )' elif [ "x$1" = "xcbal" ] then if [ $# -lt 6 ] then usage fi shift transfer_mode=$1 shift preserve_lum=$1 shift cyan_red=$1 shift magenta_green=$1 shift yellow_blue=$1 shift doing_something=y x=$x' (gimp-color-balance the-drawable '"$transfer_mode"' '"$preserve_lum"' '"$cyan_red"' '"$magenta_green"' '"$yellow_blue"' )' elif [ "x$1" = "xbrightcont" ] then if [ $# -lt 3 ] then usage fi shift brightness=$1 shift contrast=$1 shift doing_something=y x=$x' (gimp-brightness-contrast the-drawable '"$brightness"' '"$contrast"' )' elif [ "x$1" = "xperspective" ] then if [ $# -lt 13 ] then usage fi shift ulx=$1 shift uly=$1 shift urx=$1 shift ury=$1 shift llx=$1 shift lly=$1 shift lrx=$1 shift lry=$1 shift direction=$1 shift interpolation=$1 shift recursion=$1 shift clip=$1 shift doing_something=y x=$x' (gimp-drawable-transform-perspective the-drawable '"$ulx"' '"$uly"' '"$urx"' '"$ury"' '"$llx"' '"$lly"' '"$lrx"' '"$lry"' '"$direction"' '"$interpolation"' 0 '"$recursion"' '"$clip"' )' elif [ "x$1" = "xcomment" ] then if [ $# -lt 2 ] then usage fi shift comment=$1 shift doing_something=y else usage fi done if [ "x$out_file" = "x-" ] then x=$x' (set! the-display ( car ( gimp-display-new the-image)))' x=$x' (gimp-displays-flush)' else x=$x' ( file-jpeg-save 1 the-image the-drawable out-file out-file' x=$x' 0.75 0.0 1 0 "'$comment'" 0 1 0 0' x=$x' )' x=$x' ( gimp-quit 0 )' fi x=$x')' if [ "x$FORREST_VERBOSE" != "x" ] then echo teco01 $x fi if [ "x$FORREST_STRACE" != "x" ] then STRACE="strace -f" else STRACE= fi if [ "x$doing_something" = "xy" ] then if [ "x$out_file" = "x-" ] then $STRACE gimp -s -c -b "$x" else $STRACE gimp -i -s -c -b "$x" echo "$in_file -- $out_file" fi else if [ "x$out_file" = "x-" ] then echo $STRACE gimp $in_file $STRACE gimp $in_file else cp $in_file $out_file echo "$in_file -- $out_file" fi fi