Page 1 of 1

Slice image and name by row and column

Posted: 2019-06-10T02:36:43-07:00
by mkuhfuss
Hi,

i need to slice an image. For example:
full.jpg = 7296x5472

1 slice = max. 1024x1024px

At the moment i use this command:

Code: Select all

convert -crop 1024x1024 full.jpg %d.jpg
With this i got imagename like:
1.jpg
2.jpg


But i need the name with row and column index. For example:

First row:
0_1.jpg
0_2.jpg

Second row:
1_1.jpg
1_2.jpg


My Version is: 6.9.7-4

Thanks in Advance
Markus

Re: Slice image and name by row and column

Posted: 2019-06-10T03:42:16-07:00
by snibgo

Re: Slice image and name by row and column

Posted: 2019-06-10T05:42:12-07:00
by mkuhfuss
Thansk for your answer…
This works for me:

Code: Select all

convert 7296.jpg -crop 1024x1024 -set filename:tile "%[fx:page.y/1024]_%[fx:page.x/1024]" 0_%[filename:tile].jpg
No i need to resize all Images in a loop and than slice these Thumbnails:

Example:

Original.jpg = 7296x5472px

First i need to resize this full Image to:
5472px (75%)
3648px (50%)
1824px (25%)
912px (12,5%)

Every one of these thumbnails i need to slice in 1024X1024px.

My command for resizing so far:
I realized that the following command is very slow. Is there a faster approach?

Code: Select all

convert 7296.jpg \
 \( +clone -resize 75% -write thumb_75.jpg +delete \) \
 \( +clone -resize 50% -write thumb_50.jpg +delete \) \
  \( +clone -resize 25% -write thumb_25.jpg +delete \) \
  -resize 12.5% thumb_12_5.jpg
Next my current command doesn't realy work :-(

Code: Select all

files=(thumb_*.jpg)
total=${#files[@]}
i=0
for f in "${files[@]}"; do
	echo index $i
	convert "$f" -crop 1024x1024 -set filename:tile "%[fx:page.y/1024]_%[fx:page.x/1024]" "$i"_%[filename:tile].jpg
	i=$(( i + 1 ))
done
I want to loop the 4 files (5472px, 3648px, 1824px,912px) and i expect this result:

5472px:
0_0_1.jpg
0_0_2.jpg
...
next row:
0_1_1.jpg
0_1_2.jpg
...

3648px:
1_0_1.jpg
1_0_2.jpg
...
next row:
1_1_1.jpg
1_1_2.jpg
...


and so on...

Re: Slice image and name by row and column

Posted: 2019-06-10T05:56:29-07:00
by mkuhfuss
Ok with this it works. But resizing is still very slow.
And it would be nice if i could do this in one command/Batch script!

Code: Select all

convert 7296.jpg \
\( +clone -resize 100% -write thumb_1.jpg +delete \) \
 \( +clone -resize 75% -write thumb_2.jpg +delete \) \
 \( +clone -resize 50% -write thumb_3.jpg +delete \) \
  \( +clone -resize 25% -write thumb_4.jpg +delete \) \
  -resize 12.5% thumb_5.jpg

Code: Select all

files=(thumb_*.jpg)
total=${#files[@]}
i=0
for f in "${files[@]}"; do
	echo index $i
	echo file $f
	convert "$f" -crop 1024x1024 -set filename:tile "%[fx:page.y/1024]_%[fx:page.x/1024]" "$i"_%[filename:tile].jpg
	i=$(( i + 1 ))
done

Re: Slice image and name by row and column

Posted: 2019-06-10T06:08:34-07:00
by snibgo
mkuhfuss wrote:Is there a faster approach?
Instead of "-resize", you could use "-scale" or "-sample". These are faster, and usually lower-quality for ordinary photos, but may be good enough.
mkuhfuss wrote:Next my current command doesn't realy work
You increment "i" at every input file. But your required output filenames suggest you should increment "i" less often.

Re: Slice image and name by row and column

Posted: 2019-06-10T06:52:06-07:00
by mkuhfuss
Oh thank you!
-sample and -scale are faster, much more faster :-)

Quality is good enough i think too!