Page 2 of 3

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-02T07:57:37-07:00
by kimmyk
Getting close with this code:
$cmd = "/usr/bin/convert fitness.jpg \
\( ". $profile_pic ." -resize 300 -rotate -5 \) -geometry +20+20 -composite \
\( paperclip.png -rotate -5 \) -geometry +40+10 -composite \
final_image.jpg
";

I might need a bit of help :)

https://wmforum.nl/sample3.jpg


When i remove the rotation and move the clip up by -5 pixels it looks perfect, just not rotated ;-)

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-02T08:28:02-07:00
by kimmyk
Got it:
$cmd = "/usr/bin/convert fitness.jpg \
\( ". $profile_pic ." -resize 300 -alpha set -background none -rotate -5 \) -geometry +20+20 -composite \
\( paperclip.png \) -geometry +40+29 -composite \
final_image.jpg


Almost perfect :)
https://wmforum.nl/sample4.jpg

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-02T09:38:11-07:00
by fmw42
Since you are on IM 7, the syntax is slightly different. Replace "convert" with "magick".

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-02T12:48:37-07:00
by kimmyk
fmw42 wrote: 2018-11-02T09:38:11-07:00 Since you are on IM 7, the syntax is slightly different. Replace "convert" with "magick".
It works fine, but i'll change it if that is better.

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-02T13:00:08-07:00
by fmw42
Using convert with IM 7, depending upon your set-up, may be actually using IM 6 code. In this example, there is likely no difference. But best to switch to using "magick" when using IM 7 to get all the newer features of IM 7.

For other tools, you will need to preface them with magick. So in IM 7, it would be magick compare, magick mogrify, magick montage, magick identify, etc. But not magick convert. Here it is only magick.

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-02T13:38:37-07:00
by kimmyk
Thanks Fred. My script is now done and I'll implement it for whatever feature soon.

This is the final code (for now)

$cmd = "/usr/bin/magick happy-bd.jpg \
\( ". $profile_pic ." -resize 200 -alpha set -background none -rotate -5 \) -geometry +20+10 -composite \
\( paperclip.png \) -geometry +30+15 -composite \
\( -background none -fill white -font \"./lib/impact.ttf\" -size 500x100 -gravity Center caption:'Kim, we hope to see you soon!\nCODE: FDGHF4G65' \) -gravity South -geometry +0+150 -composite \
-quality 40 final_image.jpg
";

Although it does look exactly how I wanted it to look, I think the thumb/profile image could be better. It's kinda dull/boring as is. I've seen many more fun projects using this stuff. Like the (note, not my taste) "IM Legend" - bookcovers you saw for a while on FB walls. It was done pretty well, getting those images ligned up almost perfect.

I got some cool ideas when i saw that half transparent glassy 3d buttons in the IM help sections.

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-02T14:31:13-07:00
by fmw42
In the future, when you need some help, it would be good idea to post the input images independently and not in one composite. That way, we can try to reproduce your result from your actual input.

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-02T15:43:44-07:00
by kimmyk
fmw42 wrote: 2018-11-02T14:31:13-07:00 In the future, when you need some help, it would be good idea to post the input images independently and not in one composite. That way, we can try to reproduce your result from your actual input.
Will do, np

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-04T04:20:36-07:00
by kimmyk
Hi Fred, I do actually have a question about an option that bugs me :-)

This is my final code now (urls removed):

/usr/bin/magick /happy-bd.jpg \
\( https://91e8b811d51b1474a21fbe.jpg -resize 200 -bordercolor white -border 6 -bordercolor grey60 -border 1 -alpha set -background none -rotate -5 \) -geometry +20+10 -composite \
\( /paperclip.png \) -geometry +30+17 -composite \
\( -background none -fill white -font ./lib/felt.ttf -size 480x100 -gravity Center caption:'Hi {{NAME}}, we hope to see you soon!
CODE: FREEDESSERT' -trim -bordercolor rgba\(0,0,0,0.5\) -border 10 \) -gravity South -geometry +0+120 -composite \
-quality 65 /1541329006.jpg



The last section which adds the text has a 50% transparent black background, but I'm not able to succesfully add a border around that rectangle. When i add/use things like the following the best I got was it placed an entire rectangle of the border/stroke color under the text again instead of just the outline around my 50% black background:

-fill none -stroke white
or
-stroke white -strokewidth 1
or (a variation of)
-shave




I did have a working version of this with the PHP version where i used draw based on XY co-ordinated, but now i am using this cmd version (which is much better).

Am I missing some basic fundamental and correct way of writing this code?


Last but not least, if you don't mind i have two other questions. Don't want to start a new thread just for those:
1. For a digital loyalty card, we now use 5 JPGs each corresponds to a stamp (1-5), but I think this would work great with unlimited stamps (max. is set in script settings). If I were to use a stamp.png file (much like the paperclip in the above sample) and want to put those in a random (natural stamped) XY(+slightly rotated) position in a certain area (like lower third of image), what would you suggest is the best way for that? Clone, Tile, Copy? I would basicly check with my script how many stamps a person already has and then add one to it until the end is reached in which case they have 0 again. I can use a while loop to print the X stamps.


2 (solved, sort of). Can you point me to a manual where i can find what these syntaxes preceeded by : mean, like rose: in this sample "convert rose: -crop". I think i read it means it is stored in cache and that name (rose) can be anything, but when do you use that? And then there were all those other "name:" variations I saw, but not where i could find the explanantions.
Edit: found another sample just now "xd:" in
convert xc:red -bordercolor yellow -border 1 \
-filter Gaussian +distort SRT 33,0 -normalize dot_distort.jpg


Edit2: I now know canvas: is the newer xd:, but still not sure what to do with it:) I assume rose: is the name of the canvas(?)

Edit3 (just in case others read this who are not sure what it means:
An image name ending with a colon ":" is a built-in facility of ImageMagick, rather than a file that contains an image.
"rose:" is an image that is built-in to ImageMagick. Instead of using a filename, "rose:" simply provides a standard test image. Other built-in images include "wizard:" and "logo:".
https://www.imagemagick.org/discourse-s ... hp?t=30201



I appreciate your awesome willingness to keep sharing all these years, almost all threads I read have your name in it:)

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-04T05:59:14-07:00
by GeeMack
kimmyk wrote: 2018-11-04T04:20:36-07:00The last section which adds the text has a 50% transparent black background, but I'm not able to succesfully add a border around that rectangle. When i add/use things like the following the best I got was it placed an entire rectangle of the border/stroke color under the text again instead of just the outline around my 50% black background:
To add a border around a transparent image without the border color filling the background, make sure you set the compose method to "copy" before applying the border. The first command here will fill the background with the border color. The second will just add the border around the image.

Code: Select all

magick -background none -pointsize 100 label:"ABC 123" -border 10 doesntwork.png

magick -background none -pointsize 100 label:"ABC 123" -compose copy -border 10 works.png

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-04T06:19:14-07:00
by kimmyk
As a part of my "larger scheme" this still creates a solid black rectangle:
...
\( -background none -fill white -font ./lib/felt.ttf -size 480x100 -gravity Center caption:'Hi {{NAME}}, we hope to see you soon!' -trim -bordercolor rgba\(0,0,0,0.5\) -border 10 -compose copy -border 10 \) -gravity South -geometry +0+120 -composite \
...

When pushed outside of the () it will create a border around the entire image as well as making the text rectangle black instead of 50% opaque

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-04T06:29:35-07:00
by snibgo
As GeeMack says, but note that kimmyk's command uses a composite after that border operation, so that should include "-compose Over" because the default won't be used.

For builtin images like "rose:", see http://www.imagemagick.org/script/forma ... tin-images .

The same page describes pseudo-image formats such as "xc:".

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-04T06:33:59-07:00
by GeeMack
kimmyk wrote: 2018-11-04T06:19:14-07:00As a part of my "larger scheme" this still creates a solid black rectangle:
...
\( -background none -fill white -font ./lib/felt.ttf -size 480x100 -gravity Center caption:'Hi {{NAME}}, we hope to see you soon!' -trim -bordercolor rgba\(0,0,0,0.5\) -border 10 -compose copy -border 10 \) -gravity South -geometry +0+120 -composite \
...
(Writing while snibgo was replying...) After adding the border you'll have to change the compose method back to "over", or whatever compose method is required before doing another composite...

Code: Select all

... -compose copy -border 10 -compose over ...

Re: Recreate a driver's license/passes with image and text

Posted: 2018-11-04T06:48:47-07:00
by kimmyk
That works :-)

...
\( -background none -fill white -font ./lib/felt.ttf -size 480x100 -gravity Center caption:'Hi {{NAME}}, we hope to see you soon!' -trim -bordercolor rgba\(0,0,0,0.5\) -border 10 -compose copy -bordercolor black -border 1 -compose over \) -gravity South -geometry +0+120 -composite \
...


Thanks.

Re: Recreate a driver's license/passes with image and text

Posted: 2019-04-05T13:51:01-07:00
by fmw42
Draw the text inside your parenthes for for my image.jpg using -annotate or create a new transparent image with your text using label:

See https://imagemagick.org/Usage/text/