Bash with Imagemagick script HELP [Solved]

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jo-shva
Posts: 4
Joined: 2012-01-29T13:01:01-07:00
Authentication code: 8675308

Bash with Imagemagick script HELP [Solved]

Post by jo-shva »

I am on ArchLinux with Imagemagick 6.7.4-0 Q16

I have written my first bash script and it uses imagemagick to crop/scale/and composite png's for a Gtk theme I am working on. The script calls for the user to input their monitor screen Width with multiple screen Height dimensions for imagemagick to work its magick on the image files. What I would like is to have the script only ask once for the monitor Width and automagickly use the same dimension for each individual cut/crop etc. I hope I am making sence. Here is a sample of the original code. It works but, the script uses 6 different Heights and only 1 Width.

Code: Select all

echo "Enter your screen WIDTH followed by the HEIGHT of x34:"
read -e MTY
convert -size $MTY metacity-1/metacity_light_layer.png -scale $MTY! +profile '*' metacity-1/light_layer.png
convert -size $MTY metacity-1/metacity_light_layer_inactive.png -scale $MTY! +profile '*' metacity-1/light_layer_inactive.png
convert -size $MTY+0+0 gtk-3.0/assets/WindowFillD.png -crop $MTY+0+0! +profile '*' metacity-1/unfocused.png
cp metacity-1/unfocused.png metacity-1/focused.png
cp metacity-1/unfocused.png xfwm4/focused.png
composite metacity-1/light_layer.png metacity-1/focused.png metacity-1/light_focused.png
composite metacity-1/light_layer_inactive.png metacity-1/unfocused.png metacity-1/unfocused.png
Here is the same code with a sample of what I am attempting. This piece of code doesnt work at all.

Code: Select all

echo "Enter your screen WIDTH:"
read -e WDTH
MTY=$WDTH"x34"
MTYB=$WDTH"x34+0+0"
convert -size $MTY metacity-1/metacity_light_layer.png -scale $MTY! +profile '*' metacity-1/light_layer.png
convert -size $MTY metacity-1/metacity_light_layer_inactive.png -scale $MTY! +profile '*' metacity-1/light_layer_inactive.png
convert -size $MTYB gtk-3.0/assets/WindowFillD.png -crop $MTYB! +profile '*' metacity-1/unfocused.png
Unfortunatly this doesnt work. Imagemagick outputs the same images as the original files without the magic.
Help
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Bash with Imagemagick script HELP

Post by fmw42 »

Sorry don't take this the wrong way, but... why do you start with -size? I don't think that will help. I believe that it is outdated and only worked in the past for JPG reading in images. It is now replaced with -define jpg:... See http://www.imagemagick.org/Usage/formats/#jpg_read.

So try removing the -size from your command. I don't know if it is a problem or just skipped for non-jpg format images.

Try

MTY="${WDTH}x34"
MTYB="${WDTH}x34+0+0"

convert metacity-1/metacity_light_layer.png -scale ${MTY}\! +profile '*' metacity-1/light_layer.png

See if that works.

I am not an expert on profiles, but see http://www.imagemagick.org/Usage/formats/#profiles

See also -strip, http://www.imagemagick.org/script/comma ... .php#strip, to remove profiles and other metadata.

I would recommend that you try each command in a terminal before trying to put them together in a script. Then you can see where things fail. You can even add echo to read back your variables.
jo-shva
Posts: 4
Joined: 2012-01-29T13:01:01-07:00
Authentication code: 8675308

Re: Bash with Imagemagick script HELP

Post by jo-shva »

Thanks for getting back to me so quick.

Code: Select all

MTY="${WDTH}x34"
MTYB="${WDTH}x34+0+0"
That worked.
I read the info you pointed out and I removed the
-size $MTY
from the begining of each line, and everything works fine. Im not sure after reading if the
+profile '*'
part of the code is nessasary. But I cant be sure. This is my first script and the first time that i have used Imagemagick.

I would like to ask about another part of my script

Code: Select all

convert gtk-2.0/widgets/Frame/WindowFillD.png -scale 500x300 +profile '*' gtk-2.0/widgets/Frame/WindowFillD.png
The file .../WindowFillD.png is scaled at the beging of the script to an individuals monitor res. For example: 1366x768. Here at the end of the script I call imagemagick to scale it down. I used an arbitrary size (-scale 500x300). (The reason is Gtk2 doesnt handle an image so large very well, It slows the system down. But when I shrink the image and let Gtk scale it up, the system isnt sluggish.) How might I change that and have it scaled down to 1/3 of the earlier image ie..."1366x768 divided by 1/3" . And what would I call to give me the best compression while keeping as much detail from the larger sized image?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Bash with Imagemagick script HELP

Post by fmw42 »

use -resize rather than -scale. Resize does an interpolated scaling, while -scale just averages blocks of pixels. With -resize, you can choose from many different -filter types, but the default has generally been selected for the best general quality for different picture types. But you can play with that for your type of picture.

see
http://www.imagemagick.org/Usage/resize/
jo-shva
Posts: 4
Joined: 2012-01-29T13:01:01-07:00
Authentication code: 8675308

Re: Bash with Imagemagick script HELP

Post by jo-shva »

Thanks for pointing me to the -resize option. The image does look better than with the -scale option especially when resizing the image back up to 100%.
Thanks for all your help.
jo-shva
Posts: 4
Joined: 2012-01-29T13:01:01-07:00
Authentication code: 8675308

Re: Bash with Imagemagick script HELP [SOLVED]

Post by jo-shva »

maked as solved.
Post Reply