Crop and extend - page offsets are too high - incorrect names of tiles

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
bravis
Posts: 3
Joined: 2019-09-01T08:07:18-07:00
Authentication code: 1152

Crop and extend - page offsets are too high - incorrect names of tiles

Post by bravis »

I have this command:

Code: Select all

convert "lenna256x256.png" -verbose -crop "170x180" \
	-background blue \
	-extent "170x180"  \
	-format "jpg" -quality 60 \
	-set filename:f "./temp_dir/rgba|%[fx:w]x%[fx:h]|%[fx:page.width]x%[fx:page.height]|%[fx:page.x/170]_%[fx:page.y/180]" \
	"%[filename:f].jpg"
And I want to create 4 same-sized tiles of size 170x180. Only one tile will be fully filled, others use extent and area will be filled blue.

So far so good, tiles of same sizes are created.

However, problem is with page.x and page.y because I cannot create correct naming. What I got from verbose is this:

Code: Select all

lenna256x256.png=>./temp_dir/rgba|170x180|256x256|0_0.jpg[0] PNG 256x256=>170x180 256x256+0+0 8-bit Grayscale Gray 4039B 0.063u 0:00.062
lenna256x256.png=>./temp_dir/rgba|170x180|506x256|1.97647_0.jpg[1] PNG 256x256=>170x180 506x256+336+0 8-bit sRGB 2516B 0.047u 0:00.042
lenna256x256.png=>./temp_dir/rgba|170x180|256x606|0_2.36667.jpg[2] PNG 256x256=>170x180 256x606+0+426 8-bit sRGB 2614B 0.031u 0:00.031
lenna256x256.png=>./temp_dir/rgba|170x180|506x606|1.97647_2.36667.jpg[3] PNG 256x256=>170x180 506x606+336+426 8-bit sRGB 1614B 0.015u 0:00.019
It should create tiles with names 0_0, 0_1, 1_0 and 1_1. Even if I use ceil or floor for page.x and page.y, it wont be correct (eg. 2.36667 is not 1). What is wrong? What is the reason for dimensions 506 and 606?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Crop and extend - page offsets are too high - incorrect names of tiles

Post by snibgo »

What version of IM? On what platform?

ceil() and floor() work fine.

"-extent" has increased the canvas size, hence 506x606 etc.

I suggest that you shouldn't use pipe symbol "|" in filenames. Some OS's won't permit it.
snibgo's IM pages: im.snibgo.com
bravis
Posts: 3
Joined: 2019-09-01T08:07:18-07:00
Authentication code: 1152

Re: Crop and extend - page offsets are too high - incorrect names of tiles

Post by bravis »

I have ImageMagick 6.9.10-11 Q16 x86_64 2018-09-08.

Yes, ceil and floor works fine, but the overall tile index is wrong.

Note: I know about the pipe symbol, I have just used it for easier reading.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Crop and extend - page offsets are too high - incorrect names of tiles

Post by snibgo »

bravis wrote:... but the overall tile index is wrong
What is wrong with it? You do "-extent" (which changes page.x etc) and then set the filename. Perhaps you want to set the filename first, then use "-extent".
snibgo's IM pages: im.snibgo.com
bravis
Posts: 3
Joined: 2019-09-01T08:07:18-07:00
Authentication code: 1152

Re: Crop and extend - page offsets are too high - incorrect names of tiles

Post by bravis »

Thank you, it works. Set filename before -extent is correct.

I did not think that the order of arguments is important :/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop and extend - page offsets are too high - incorrect names of tiles

Post by fmw42 »

They are even more important in Imagemagick 7.
Post Reply