Trim transparency off bottom and right

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
MrT
Posts: 2
Joined: 2014-10-09T04:18:59-07:00
Authentication code: 6789

Trim transparency off bottom and right

Post by MrT »

I am using IM to convert a large number of dds files to png, the x and y size of a dds file need to be a power of 2 but png files don't and to reduce the file sizes i want to crop/trim off any transparency off the bottom and right of the images. I need to leave the top and left as they are, otherwise i will screw up my UV co-ordinates of the sprites that are on the png. Is there any way of doing this with IM or will i have to write my own utility to do this?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trim transparency off bottom and right

Post by fmw42 »

see trimming just one side. you can do it twice, once for each side.

http://www.imagemagick.org/Usage/crop/#trim_oneside

If on Linux/MacOSX or Windows with Cygwin, see my script trimmer at the link below. It allows you to do that for any number of sides.
MrT
Posts: 2
Joined: 2014-10-09T04:18:59-07:00
Authentication code: 6789

Re: Trim transparency off bottom and right

Post by MrT »

Thanks for the info, for reference i used the following command line to get it working :-

convert.exe file.dds -gravity West -background white -splice 5x0 -background black -splice 5x0 -trim +repage -chop 5x0 -gravity north -background white -splice 0x1 -background black -splice 0x1 -trim +repage -chop 0x1 file.png
Post Reply