ID passport

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
shalmoo
Posts: 3
Joined: 2011-11-11T02:43:22-07:00
Authentication code: 8675308

ID passport

Post by shalmoo » 2011-11-11T14:12:32-07:00

I need to create a photo, containing four portraits, i.e. a classic ID passport photo.
FOr exmaple, I need to convert this photo:
Image
I have constructed the following command:

Code: Select all

convert -size 300x400 xc:white -draw "image SrcOver 10,10 135,185 'src.jpg'" -draw "image SrcOver 10,205 135,185 'src.jpg'" -draw "image SrcOver 155,10 135,185 'src.jpg'" -draw "image SrcOver 155,205 135,185 'src.jpg'" id_passport.jpg
The result is:
Image
As you can see, the photos are stretched.

How do I crop the photo inside one command? Something like this:
Image
Of cource I can first do the crop command and save the intermediate photo to disk, but it is a waste of time and quality, I need everything in one single command. Thank you.

User avatar
fmw42
Posts: 24125
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ID passport

Post by fmw42 » 2011-11-11T15:09:20-07:00

If I were doing it, I would do it as follows:


convert -size 300x400 xc:white \
\( src.jpg -gravity center -crop 243x333+0+0 +repage -resize 135x185! \) \
\( -clone 0 -clone 1 -gravity northwest -geometry +10+10 -composite \) \
\( -clone 2 -clone 1 -gravity northeast -geometry +10+10 -composite \) \
\( -clone 3 -clone 1 -gravity southeast -geometry +10+10 -composite \) \
\( -clone 4 -clone 1 -gravity southwest -geometry +10+10 -composite \) \
-delete 0-4 src_result1.jpg


or


convert -respect-parenthesis -size 300x400 xc:white \
\( src.jpg -gravity center -crop 243x333+0+0 +repage -resize 135x185! \) \
\( -page +10+10 -clone 1 \) \
\( -page +155+10 -clone 1 \) \
\( -page +155+205 -clone 1 \) \
\( -page +10+205 -clone 1 \) \
-delete 1 -background white -flatten src_result2.jpg


see
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/layers/#flatten

http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/basics/#sequence
http://www.imagemagick.org/Usage/basics/#clone

shalmoo
Posts: 3
Joined: 2011-11-11T02:43:22-07:00
Authentication code: 8675308

Re: ID passport

Post by shalmoo » 2011-11-11T17:06:10-07:00

Thank you very much, fmw!I like second variant.
OK, now If I want to do the set of three images, like this:
Image
how do I construct the command? I tried to do this:

Code: Select all

convert -respect-parenthesis -size 300x400 xc:white	
			( src.jpg -gravity center -crop 243x333+0+0 +repage -resize 135x185! ) 
						( -page +10+10 -clone 1 ) 
						( -page +155+10 -clone 1 ) 
			( src.jpg -gravity center -crop 391x258+0+0 +repage -resize 280x185! ) 
						( -page +10+205 -clone 2 ) 
	-delete 1 -delete 2 -background white -flatten -quality 99 id_passport.jpg	
But it failed, although seems like I follow the syntax you suggest. What is wrong with my command?

shalmoo
Posts: 3
Joined: 2011-11-11T02:43:22-07:00
Authentication code: 8675308

Re: ID passport

Post by shalmoo » 2011-11-11T18:27:01-07:00

I got it!!!

Code: Select all

convert -respect-parenthesis -size 300x400 xc:white src.jpg 
( -clone 1 -gravity center -crop 243x333+0+0 +repage -resize 135x185! ) 
( -clone 1 -crop 391x258+0+0 +repage -resize 280x185! ) 
     ( -page +10+10 -clone 2 ) 
     ( -page +155+10 -clone 2 ) 
     ( -page +10+205 -clone 3 ) 
-delete 1-3 -background white -flatten -quality 99 id_passport3.jpg	

ligongl
Posts: 1
Joined: 2018-06-28T18:25:14-07:00
Authentication code: 1152

Re: ID passport

Post by ligongl » 2018-06-28T18:27:44-07:00

would you be kind enough to re-format the following command for MS-DOS ? Thank you.

magick convert -respect-parenthesis -size 300x400 xc:white src.jpg
( -clone 1 -gravity center -crop 243x333+0+0 +repage -resize 135x185! )
( -clone 1 -crop 391x258+0+0 +repage -resize 280x185! )
( -page +10+10 -clone 2 )
( -page +155+10 -clone 2 )
( -page +10+205 -clone 3 )
-delete 1-3 -background white -flatten -quality 99 id_passport3.jpg

User avatar
fmw42
Posts: 24125
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ID passport

Post by fmw42 » 2018-06-28T19:36:15-07:00

try

Code: Select all

magick -respect-parenthesis -size 300x400 xc:white src.jpg ^
( -clone 1 -gravity center -crop 243x333+0+0 +repage -resize 135x185! ) ^
( -clone 1 -crop 391x258+0+0 +repage -resize 280x185! ) ^
( -page +10+10 -clone 2 ) ^
( -page +155+10 -clone 2 ) ^
( -page +10+205 -clone 3 ) ^
-delete 1-3 -background white -flatten -quality 99 id_passport3.jpg

Post Reply