Page 1 of 1
The different styles of auto naming the tiles (-crop %02d)
Posted: 2008-07-09T07:31:20-07:00
by forumim
I have a big image and crop it in little tiles:
Code: Select all
exec("convert input.jpg -crop 256x256 mytile_%02d.jpg", $arr, $err);
Now the generated tiles are named:
mytile_
01.jpg, mytile_
02.jpg, mytile_
03.jpg ...
I would like, that the tiles in the
first line are named:
mytile_
01-01.jpg, mytile_
01-02.jpg, mytile_
01-03.jpg ...
Tiles in the
second line:
mytile_
02-01.jpg, mytile_
02-02.jpg, mytile_
02-03.jpg ...
Third line:
mytile_
03-01.jpg, mytile_
03-02.jpg, mytile_
03-03.jpg ...
And so on...
How can I do that?
Re: The different styles of auto naming the tiles (-crop %02d)
Posted: 2008-07-09T17:55:36-07:00
by anthony
That is not so easy, as the output filename only allows the use of
a single %d printf() format to specify the image size.
What you may need to do is either...
- rename the files afterward converting the sequence
01 02 03 04 05....
into
01-01 01-02 ... 01-30 02-01 02-02 ...
etc. You will need to know how many tiles per row was generated though.
- JPEG does not save the 'offset' from which an image is cropped. But PNG format does (it is also not color lossy). You can output the images as PNG, then read the virtual canvas offset, and from that determine the 'tile' position, allowing you to rename the image, or resave as JPEG images of the right name.
- You can record the images virtual canvas offset
(position from where the image was cropped) into the images JPEG comment string before you remove that offset from the resulting image (JPEG does not store the virtual canavs information, so it losses that information)
Code: Select all
convert input.jpg -crop 256x256 -set comment '%O' +repage mytile_%02d.jpg"
identify -format '%f %c' mytile_%02d.jpg
- In a FUTURE version of IM, you may be able to specify a filename for the output file (perhaps as a %s string). This might be able to also be able to be -set and the tile number calculated using %[FX:...] escapes.
However at this time the filename is not adjustable using -set, AND the X and Y virtual offsets of the image is not available within FX expressions. I have put in a request for the later, so the tile position can be at least calculated and recorded in comments. You may like to request the former '%s' to set the save images basename
Re: The different styles of auto naming the tiles (-crop %02d)
Posted: 2008-07-10T00:55:16-07:00
by forumim
Thanks a lot!
A such skill in a FUTURE version of IM would be great.
So I will looking forward to the next versions of IM,
till then I rename the files afterward.
(I know how many tiles per row was generated)
Re: The different styles of auto naming the tiles (-crop %02d)
Posted: 2008-07-10T02:20:01-07:00
by Bonzo
Another way would be to crop the image into rows and then crop the rows into tiles; you could then name each row whatever you wanted.
Re: The different styles of auto naming the tiles (-crop %02d)
Posted: 2008-07-10T06:32:54-07:00
by Bonzo
I am slow sometimes; if you are using php you could modify this code to rename the images:
http://www.rubblewebs.co.uk./imagemagic ... _f_42.html