Page 1 of 1

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

Posted: 2019-09-01T08:16:28-07:00
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?

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

Posted: 2019-09-01T10:05:18-07:00
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.

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

Posted: 2019-09-01T10:16:56-07:00
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.

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

Posted: 2019-09-01T11:16:17-07:00
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".

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

Posted: 2019-09-01T11:26:59-07:00
by bravis
Thank you, it works. Set filename before -extent is correct.

I did not think that the order of arguments is important :/

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

Posted: 2019-09-01T14:41:47-07:00
by fmw42
They are even more important in Imagemagick 7.