Page 1 of 3

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

Posted: 2018-11-01T13:19:15-07:00
by kimmyk
Hi all, I've been using the basic stuff of imagemagick for opver a decade and love it, but i want to make something more difficult than just text on an image;-)

I'd like to use an image (from a URL), crop/mask that and put it on the right side of an image, like a driver's license or any other sort of ID, then print text (name) next to it.

Is there a preferred (thus fastest and gentle on the server) way of doing this? Can it be done in one convert cmd line? Or I need one for the masking, one for the positioning on the rectangle and 1 for the text?

Thanks.

I've studied this but it is mostly centered thumbs:
http://www.imagemagick.org/Usage/thumbnails/

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

Posted: 2018-11-01T13:53:57-07:00
by snibgo
Yes, probably a single command.

Please read https://www.imagemagick.org/discourse-s ... f=1&t=9620

Without knowing your version and platform, and your sample inputs, we can't give specific advice.

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

Posted: 2018-11-01T14:29:08-07:00
by kimmyk
Thanks, I'll read up. Should i ask my tech guys to upgrade imagemagick on my server? Will my current scripts still work if I do?

Server is:
Apache 2.4.35
Php 5.6.38

imagick module version 3.4.3
imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
Imagick compiled with ImageMagick version ImageMagick 6.7.8-9 2016-06-16 Q16 http://www.imagemagick.org
Imagick using ImageMagick library version ImageMagick 6.7.8-9 2016-06-16 Q16 http://www.imagemagick.org
ImageMagick copyright Copyright (C) 1999-2012 ImageMagick Studio LLC
ImageMagick release date 2016-06-16
ImageMagick number of supported formats: 209
ImageMagick supported formats 3FR, A, AAI, AI, ART, ARW, AVI, AVS, B, BGR, BGRA, BMP, BMP2, BMP3, BRF, C, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CRW, CUR, CUT, DCM, DCR, DCX, DDS, DFONT, DNG, DOT, DPX, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FAX, FITS, FRACTAL, FTS, G, G3, GIF, GIF87, GRADIENT, GRAY, GROUP4, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, ICB, ICO, ICON, INFO, INLINE, IPL, ISOBRL, J2C, J2K, JNG, JP2, JPC, JPEG, JPG, JPX, K, K25, KDC, LABEL, M, M2V, M4V, MAC, MAP, MAT, MATTE, MEF, MIFF, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, O, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG24, PNG32, PNG8, PNM, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PTIF, PWP, R, RADIAL-GRADIENT, RAF, RAS, RGB, RGBA, RGBO, RLA, RLE, SCR, SCT, SFW, SGI, SHTML, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UBRL, UIL, UYVY, VDA, VICAR, VID, VIFF, VST, WBMP, WMF, WMV, WMZ, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, Y, YCbCr, YCbCrA, YUV

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

Posted: 2018-11-01T14:55:03-07:00
by snibgo
v6.7.8-9 is very old. I suggest you upgrade.

If you upgrade to the latest v6, or v7 with legacy programs, your old scripts might work. But you should test them all.

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

Posted: 2018-11-01T15:52:14-07:00
by fmw42
@kimmyk. I hope you are not trying to forge IDs. This question's motivation seems a bit suspicious.

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

Posted: 2018-11-01T15:55:56-07:00
by kimmyk
No no, not at all, haha.
I'm a Facebook Messenger developer and I use dynamic images to do cool stuff. I'm thinking of making fun coupons with peoples faces on it besides just their names, stuff like that.

The title's sample was the closest I could think of as to what i want to do. Just fun stuff: fitness passes, birthday cards etc. 100% fun stuff, none serious. No worries:)

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

Posted: 2018-11-01T16:02:13-07:00
by fmw42
This does not answer your question, but if you are interested in various holiday cards, see my bash script, bumptext, at my link below.

See also
https://imagemagick.org/Usage/annotating/
https://imagemagick.org/Usage/text/#annotate
https://imagemagick.org/Usage/text/#draw
https://imagemagick.org/Usage/draw/

With annotate or draw you use or create a background image first, then add the text in the location you want. With draw you can add lines as well as text or can even insert images. Otherwise, you can use -composite to place a smaller foreground image into the larger background image.

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

Posted: 2018-11-01T16:08:12-07:00
by fmw42
Perhaps if you make a mockup in GIMP or Photoshop and provide the images and text, we can guide you how to reproduce that in ImageMagick.

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

Posted: 2018-11-01T16:27:55-07:00
by kimmyk
I'll have a look. Love what you did with the shirt displacement map. Impressive stuff. I sold shirts and use mockups all the time, these look like they're pretty handy.

As far as the text effects, I have been doing those for more than 12 years now so I got that pretty much covered in all sorts of variations. It's time to step up my game ;-)

Sample, ok...
https://wmforum.nl/sample.jpg

Those would be 3 images (background (gradient for sample purpose), photo (red square), and maybe the paperclip (optional)) and the text.

As said, the text would be easy, i already have that is various ways for my users.


Cheers.

ps. I see you edited your post while i was photoshopping. I've read all those docs but with your guidance as to what to do first I'll have another look.

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

Posted: 2018-11-01T16:30:51-07:00
by kimmyk
Oh, and the red square, that would be an image that I have to make like that, from totally different dimensions (love your smartcrop which I was looking into)

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

Posted: 2018-11-01T17:59:23-07:00
by fmw42
kimmyk wrote: 2018-11-01T16:30:51-07:00 Oh, and the red square, that would be an image that I have to make like that, from totally different dimensions (love your smartcrop which I was looking into)
No, you can just use -draw to draw a filled in red square over the background image. See the link I sent about -draw for objects other than text.

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

Posted: 2018-11-01T18:05:01-07:00
by fmw42
You can create the orange radial gradient image first using gradient:. See https://imagemagick.org/Usage/canvas/#radial-gradient and https://www.imagemagick.org/script/gradient.php and http://www.fmwconcepts.com/imagemagick/ ... /index.php.

Then you can draw a red square. See https://imagemagick.org/Usage/draw/#primitives

Then you can composite your paperclip image over that if its background is transparent. See https://imagemagick.org/Usage/compose/#compose and https://imagemagick.org/Usage/layers/#convert.

Then you can add your test with either -annotate or -draw. See https://imagemagick.org/Usage/text/

Since the text does not overlap either the red square or the paperclip, you can add the text any time after creating the background radial gradient image.

If you get stuck, let me know and I will help or give you a solution. But it would be a good learning experience to try yourself first and then post what you have with your desired font name or file and pointsize and text words. Then I can give you pointers for optimizing it from multiple commands lines to one.

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

Posted: 2018-11-02T00:11:37-07:00
by kimmyk
I'll give it a go later today or the weekend.

Note that the gradient will in reality be an image, just quickly made a mockup in photoshop for the purpose of this thread.
Thanks again, I'll play around.

My tech guys upgraded my IM version as well:

Imagick compiled with ImageMagick version ImageMagick 7.0.8-14 Q16 x86_64 2018-10-23 https://imagemagick.org
Imagick using ImageMagick library version ImageMagick 7.0.8-14 Q16 x86_64 2018-10-23 https://imagemagick.org
ImageMagick copyright © 1999-2018 ImageMagick Studio LLC
ImageMagick release date 2018-10-23

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

Posted: 2018-11-02T00:46:04-07:00
by kimmyk
I have uploaded another mockup with my goal. Once i have figured that one out, it will serve as a base to other images too, such as submitted resume or whatever.

https://wmforum.nl/sample2.jpg

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

Posted: 2018-11-02T01:33:47-07:00
by kimmyk
So, just to share my thought process (i have to get some other work done now first), I'm leaning towards something like this (untested, I like to get as far as i can and then test).

$cmd = "/usr/bin/convert fitness.jpg \
\( http://myimg.jpg -resize 300x300 \) -geometry +20+20 -composite \
\( paperclip.gif \) -geometry +40+18 -composite \
[some text to add here still] \
final_image.jpg
";

I'm wondering though, if I can somehow mix:

-draw "image over 20,20 320,320 'http://myimg.jpg'" \
with
\( http://myimg.jpg -resize 300 \) -geometry +20+20 -composite \

So, it first crops/resizes to a width of 300, then draws the result to a max height (with the risk of the image looking terrible due to placement issues).

Something like this:
$cmd = "/usr/bin/convert fitness.jpg \
\-draw "image over 20,20 320,320 \( http://myimg.jpg -resize 300 \)" \
\( paperclip.gif \) -geometry +40+18 -composite \
[some text to add here still] \
final_image.jpg
";