Tiff tiles on original position on jpg canvas

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
martingriso
Posts: 1
Joined: 2012-10-07T10:49:48-07:00
Authentication code: 67789

Tiff tiles on original position on jpg canvas

Post by martingriso »

I have to create a tiling solution for incoming tiff files and the format of output tiles has to be jpg. Each tile has to be in separate file and located on a black canvas (same size as incoming tiff) on the same position as in the original tiff file. I found the following script that solves somewhat my problem but it is slow when incoming tiffs are large (~100MB) and therefore I'm looking for a better solution.

Code: Select all

 src=$1
 width=`identify -format %w $src`
 limit=$[$width / 256]
 echo "count = $limit * $limit = "$((limit * limit))" tiles"
 limit=$((limit-1))
 convert $src -alpha transparent -alpha extract canvas.png

 for x in `seq 0 $limit`; do
   for y in `seq 0 $limit`; do
     tile=tile-$x-$y.png
     echo -n $tile
     w=$((x * 256))
     h=$((y * 256))
     convert -debug cache -monitor $src -crop 256x256+$w+$h $tile
     convert -page +w+h canvas.png $tile -flatten $x-$y.jpg
   done
 done
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Tiff tiles on original position on jpg canvas

Post by anthony »

Try using tile crop
http://www.imagemagick.org/Usage/crop/#crop_tile
or near-equal-area cropping if you want overlaps,
http://www.imagemagick.org/Usage/crop/#crop_equal

BUT instead of using +repage to junk the canvas and offsets, fill out the canvas using a side effect of -coalesce, and junk the transparency.

For example...

Code: Select all

convert rose: -crop 35x23 \
            -set dispose background -coalesce \
            -background black -alpha remove \
            tiles_%02d.tiff
OR try -crop 3x3@

Hmmm there seems to be a bug in the coalesce as I am getting an initial white background for the 'starting canvas'
when I should be getting a transparent canvas.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Tiff tiles on original position on jpg canvas

Post by magick »

Add -background none to your command line. Does that produce expected results?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Tiff tiles on original position on jpg canvas

Post by anthony »

magick wrote:Add -background none to your command line. Does that produce expected results?
convert rose: -crop 35x23 \
-background none -set dispose background -coalesce \
-background black -alpha remove \
tiles_%02d.tiff

YES it does. However -coalesce MUST use a background none internally, as that is what is required for correct handling of GIF animations. Just about any GIF animation processing will go wrong without it.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply