resize + alpha script

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
aikiko

resize + alpha script

Post by aikiko »

Hello,

I am trying to write a script to resize wallpapers I have. The monitor is 1680*1080 but there is on the top 2x24 pixels used for the menu and 24 pixels at the bottom for the taskbar. So would like to create a script to

resize the images to 1600*978 with keeping the h x v ratio if they are bigger the this value
convert img -resize 1680x978\> img2

place the img2 on an alpha layer of 1600*978 but the problem is that i do not know the size so the draw fonction does not seem possible ...


thx
Aikiko
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: resize + alpha script

Post by fmw42 »

what do you mean by place the image on an alpha layer? where does -draw come in to the process?

can you give a full command line and/or explain your actual goal for the layout of the output image and its layer.

should it not be:

convert img -resize "1600*978\>" -gravity center -background black -extent 1600x978 img2

so that it fills out the shorter size to fill your required size.

I am puzzled where you get 1600x978?

You start with 1680*1080 then subtract (not sure if it is 48 or 72 in height from your explanation) so it should be either 1680x1032 or 1680x1008?
aikiko

Re: resize + alpha script

Post by aikiko »

1600*978 = 1600*1050 - 24x2 (top menu) - 24x1(taskbar)
The monitor is 1050 and not 1080 sorry ...

Code: Select all

convert img.jpg -resize 1600x978\> -gravity center -background transparent -extent 1600x978 img2
This thing works but the border is black instead of transparent so i had the convert the images to png so it can handle transparency, but with png it works great

I tried to find out but is the a way to make an asymetric border ? 48pixel on the top and 24 on the bottom ? Or add 48 pixels at the top and 24 on the bottom ... or any other ways ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: resize + alpha script

Post by fmw42 »

aikiko

Re: resize + alpha script

Post by aikiko »

It works.

Code: Select all

#!/bin/bash
#for img in `ls *.png`
for img in `ls *.png`
do
	convert "$img" -resize 1600x978\> -gravity center -background transparent -extent 1600x978 temp
	convert temp -gravity South  -background transparent  -splice 0x24 temp
	convert temp -gravity North  -background transparent  -splice 0x48 resized_$img
	rm temp
done
Thanks for the help
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: resize + alpha script

Post by fmw42 »

convert "$img" -resize 1600x978\> -gravity center -background transparent -extent 1600x978 temp
convert temp -gravity South -background transparent -splice 0x24 temp
convert temp -gravity North -background transparent -splice 0x48 resized_$img
rm temp
You should be able to do this all in one command without a temp


convert "$img" -resize 1600x978\> -gravity center -background transparent -extent 1600x978 \
-gravity South -splice 0x24 \
-gravity North -splice 0x48 resized_$img
Post Reply