You are not logged in.
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. I have tried to use $WIDTH, but Imagemagick wont use (exp. $WIDTHx34 etc )...I get error messages. Any help would be great. Here is my script:
#! /bin/bash
CDIR=`pwd`
cd $CDIR
echo "What is your screen resolution in pixels?"
echo " "
echo "Let me check... "
xdpyinfo | grep 'dimensions:'
echo "If those are the correct dimensions enter them below, otherwise enter the desired dimensions below."
echo " "
echo -n "Enter your screen dimensions in pixels:"
read -e RES
#pwd
convert -size $RES base_images/base.png -crop $RES+0+0! +profile '*' gtk-2.0/widgets/Frame/WindowFillD.png
cp gtk-2.0/widgets/Frame/WindowFillD.png gtk-2.0/widgets/Frame/WindowBg.png
echo "Frames resized at" $RES.
cp gtk-2.0/widgets/Frame/WindowFillD.png gtk-3.0/assets/WindowFillD.png
read -p "Done with the frames. Now lets crop and resize the bars. Press ENTER to continue..."
echo " "
echo "The first set of numbers are your screen width, x means by, and the last set is your screen height. example: 1366x768, 1366 is my screen width and 768 is my screen height. So I would enter 1366x34 on the following line."
echo " "
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
rm metacity-1/light_layer.png
rm metacity-1/light_layer_inactive.png
rm metacity-1/focused.png
echo "Metacity resized"
echo " "
echo "Enter your screen WIDTH followed by the HEIGHT of x32:"
read -e MNU
convert -size $MNU gtk-3.0/assets/WindowFillD.png -crop $MNU+0+34! +profile '*' gtk-3.0/assets/MenuFillD.png
convert -size $RES gtk-3.0/assets/WindowFillD.png -crop $RES+0+66! +profile '*' gtk-3.0/assets/WindowFillD.png
cp gtk-3.0/assets/MenuFillD.png gtk-2.0/widgets/Frame/MenuFillD.png
### XFCE LXDE panels
convert -size $MNU base_images/panel.png -crop $MNU+0+0! +profile '*' gtk-2.0/widgets/panel/panel-bg.png
cp gtk-2.0/widgets/panel/panel-bg.png panel-bg.png
echo "Menu-Bars and Panels resized"
###UNITY
echo " "
echo "Enter your screen WIDTH followed by the HEIGHT of x26:"
read -e UNU
convert -size $UNU base_images/unity_base.png -crop $UNU+0+0! +profile '*' gtk-3.0/apps/assets/unity.png
cp gtk-3.0/apps/assets/unity.png gnome-shell/panel_top.png
cp gtk-3.0/apps/assets/unity.png cinnamon/panel_top.png
convert -size $MNU base_images/panel.png -crop $UNU+0+0! +profile '*' gnome-shell/panel_bttm.png
echo "Gnome-Shell & Unity Panels resized"
###
echo " "
echo "Enter your screen WIDTH followed by the HEIGHT of x24:"
read -e XFW
convert -size $XFW xfwm4/focused.png -crop $XFW+0+8! +profile '*' xfwm4/bar.png
convert -size 8x24 xfwm4/bar.png -crop 8x24+0+0! +profile '*' xfwm4/top-left-bar.png
convert -size 8x24 xfwm4/top-left-bar.png -crop 8x24+3+0! +profile '*' xfwm4/top-left-bar.png
composite -geometry +3+0 xfwm4/top-left-bar.png xfwm4/top-left-back.png xfwm4/top-left-done.png
composite xfwm4/top-left-over.png xfwm4/top-left-done.png xfwm4/top-left-active.png
rm xfwm4/top-left-done.png
convert -size $XFW xfwm4/title-1-over.png -scale $XFW+8+0! +profile '*' xfwm4/title-1-over-layer.png
convert -size $XFW xfwm4/bar.png -crop $XFW+8+0 +profile '*' xfwm4/bar.png
composite xfwm4/title-1-over-layer.png xfwm4/bar.png xfwm4/title-1-active.png
rm xfwm4/bar.png xfwm4/title-1-over-layer.png xfwm4/focused.png
echo "Xfwm4 resized"
###
echo " "
echo "Enter your screen WIDTH followed by the HEIGHT of x14:"
read -e MAY
convert -size $MAY metacity-1/metacity_attached_light_layer.png -scale $MAY! +profile '*' metacity-1/attached_light_layer.png
convert -size $MAY metacity-1/metacity_attached_light_layer_unfocused.png -scale $MAY! +profile '*' metacity-1/attached_light_layer_unfocused.png
cp gtk-3.0/assets/MenuFillD.png metacity-1/attached.png
convert -size $MAY metacity-1/attached.png -crop $MAY+0+18! +profile '*' metacity-1/attached.png
composite metacity-1/attached_light_layer.png metacity-1/attached.png metacity-1/titlebar_fill_attached_focused.png
composite metacity-1/attached_light_layer_unfocused.png metacity-1/attached.png metacity-1/titlebar_fill_attached_unfocused.png
rm metacity-1/attached.png
rm metacity-1/attached_light_layer.png
rm metacity-1/attached_light_layer_unfocused.png
###Scale Down for Xfce Fix###
convert -size 500x300 gtk-2.0/widgets/Frame/WindowFillD.png -scale 500x300 +profile '*' gtk-2.0/widgets/Frame/WindowFillD.png
#
convert -size 500x300 gtk-3.0/assets/WindowFillD.png -scale 500x300 +profile '*' gtk-3.0/assets/WindowFillD.png
###
cp gtk-2.0/widgets/Frame/WindowFillD.png gtk-2.0/widgets/Frame/base.png
###
read -p "Finished. Done with sizing of images. Press ENTER to finish..."
Last edited by jo-shva (2012-01-29 23:15:22)
"Democracy is being allowed to vote for the candidate you dislike least." -- Robert Byrne
http://killhellokitty.deviantart.com/
Offline
$WIDTHx34 should give an error as that looks for a variable with the 8-character name "WIDTHx34". Instead you probably want $(($WIDTH x 34))
Last edited by Trilby (2012-01-29 16:41:27)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Also, perhaps I'm missing something, what are the first two lines supposed to do? It looks like it stores the working directory into a new variable (when $PWD already has that) then cd's to that directory, when it'd already be there. I think both of those lines can be dropped.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks. Changing the code as you suggested works most of the time. Here is a chunk of the script:
echo "Enter your screen WIDTH:"
read -e MTY
convert -size $(($MTYx34)) metacity-1/metacity_light_layer.png -scale $(($MTYx34))! +profile '*' metacity-1/light_layer.png
convert -size $(($MTYx34)) metacity-1/metacity_light_layer_inactive.png -scale $(($MTYx34))! +profile '*' metacity-1/light_layer_inactive.png
convert -size $(($MTYx34))+0+0 gtk-3.0/assets/WindowFillD.png -crop $(($MTYx34))+0+0! +profile '*' metacity-1/unfocused.png
It works perfect on the first few lines, but here:
$(($MTYx34))+0+0
it doesnt work. The image is a duplicate of the sorce image. Imagemagick doesnt do anything here.
"Democracy is being allowed to vote for the candidate you dislike least." -- Robert Byrne
http://killhellokitty.deviantart.com/
Offline
I have to apologize - I had a frenzy of editing my post as I just didn't read you script carefully in the first place. The $(( ... )) notation is if you want to calculate a new value by multiplying the two numbers. If you need it to actually put the two numbers with the "x" in between as convert expects you'll need
convert -size $MTY"x34+0+0"
Interestingly the following should work just as well
convert -size "$MTY"x34+0+0
In either case the quotes allow bash to determine what part is the name of the variable and what part is other symbols to be passed on to the convert command.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I tried
convert -size "$MTY"x34+0+0
and imagemagick makes no changes to the images. It doesnt crop, cut, scale, anything it just outputs the same image as the original.
"Democracy is being allowed to vote for the candidate you dislike least." -- Robert Byrne
http://killhellokitty.deviantart.com/
Offline
I have so far only been able to get imagemagick to work in the script when the input for $MTY is WIDTHxHEIGHT exp: 1366x34. Everything I have tried to allow $MTY to be only WIDTH and then combine $MTY with whatever the HEIGHT for each particular image may be...has failed. I need to find a way that imagemagick will accept the input
"Democracy is being allowed to vote for the candidate you dislike least." -- Robert Byrne
http://killhellokitty.deviantart.com/
Offline
I don't know why that wouldn't work, but as either a work around, or troubleshooting test, you could try
NEWVARIABLE=$MTY"x34+0+0"
convert -size $NEWVARIBALE ...
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
You are not going to believe this, but...that doesn't work either. Here is what I tried:
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
Even with this Imagemagick still gives me the original images without any changes. ;-((
Its gotta be something with Imagemagick. The above code is correct, isn't it? Just to make sure I didn't miss something.
"Democracy is being allowed to vote for the candidate you dislike least." -- Robert Byrne
http://killhellokitty.deviantart.com/
Offline
The variables should be assigned correctly (could always "echo $MTY $MTYB" just to make extra-sure). I can't say much about the imagemagick syntax, I've only used it for a few simple functions.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
A thought came to me. Does bash look at the sequence as an equation? $MTY is 100 then $MTYx34 has bash printing the total 3400 on the imagemagick line??
I am guessing, because I really dont know anything about progamming. But could this be the problem? Imagemagic uses the 'x' as meaning 'by' for demensions and bash is using it as multiplication. That would explain why imagemagick puts out the same image as it started with...Its getting "3400 instead of 100x34." Do you follow what i am sugesting? How can we get bash to Print exactly the numerical sequence of "100x34"?
"Democracy is being allowed to vote for the candidate you dislike least." -- Robert Byrne
http://killhellokitty.deviantart.com/
Offline
Disregard my previous post.
I just tried your last suggestion
echo $MTY $MTYB
and the script printed out the correct info. So I checked the output images and they are scaled. cropped ...magicked. I don't know what went wrong when i tried it before. I appologize.
I will make the appropriate changes throughout the script and hoppefully everything works
"Democracy is being allowed to vote for the candidate you dislike least." -- Robert Byrne
http://killhellokitty.deviantart.com/
Offline
Thanx For your help! It worked. The script is much in proved.
"Democracy is being allowed to vote for the candidate you dislike least." -- Robert Byrne
http://killhellokitty.deviantart.com/
Offline