Absolut beginner here.
I got the task to write a workflow to run on a server for a web-platform that uses RoR. Server is linux based.
I want to create an image. Basically, it's a background picture, already on the server, with two green squares, one in the down left and one in the right down corner. Inside the green squares is white text from two input fields on the website (left input text and right input text).
The user uploads a logo of their sports team to be resized and fitted into the upper-right corner.
I would basically do it like:
convert -background none -fill white -font Helvetica -pointsize 100 -size 450x -gravity center caption:“text right input“ right.png
convert -background none -fill white -font Helvetica -pointsize 100 -size 450x -gravity center caption:“text left input“ left.png
composite -gravity Center left.png base.png left_done.png
composite -gravity Center right.png base.png right_done.png
composite -gravity southeast right_done.png background.png bg_right.png
composite -gravity southwest left_done.png bg_right.png bg_left_right.png
convert Logo-upload.jpg -resize 400x230 logo_resized.png
composite -gravity NorthEast logo_resized.png bg_left_right.png done.png
This is step by step command line, how I would do it.
But there must be a more efficient way, isn't it?
I would love to here your comments. Just started out with very basic tasks programming very elementary things. Would love to learn more.
//Edit: The workflow may seem weird, but it was the easiest for me to get it pixel perfect on the background.png (1000x500px)
You can do that in one command line in ImageMagick, if you use parentheses processing. Here is an example using ImageMagick 6 in Unix syntax. See https://legacy.imagemagick.org/Usage/basics/#parenthesis
Input:
Logo:
convert IMG0005.jpg \
\( -size 450x -background green1 -fill white -font Helvetica -pointsize 100 -gravity center caption:"text right input" \) \
-gravity southeast -compose over -composite \
\( -size 450x -background green1 -fill white -font Helvetica -pointsize 100 -gravity center caption:"text left input" \) \
-gravity southwest -compose over -composite \
\( olympic-logo.gif -resize 400x230 \) \
-gravity northeast -compose over -composite \
IMG0005_composite.jpg
Result:
If on Windows, remove the back-slashes from the parentheses and change the end of line back-slash to ^.
If on ImageMagick 7, change "convert" to "magick"
Related
I'm using Perl 5.16 with ImageMagick 6.8 (probably old by now, but it works :). I'm trying to extract all 4 edge regions from one image and composite them into another image, side-by-side, oriented vertically.
I can extract edges and rotate them, but I can't get the offset in the target image right. The edges end up on top of each other. I tried x=>$marg, translate=>"$marg,0", geometry with an offset: no dice. Variables: $marg = the edge width, $im = source, $im2 = target, $ext = extracted region
# left edge
$ext=sprintf("%dx%d+%d+%d",$marg,$h,0,0);
$res=$im2->Composite(image=>$im,compose=>Over,extract=>$ext);
# top edge
$ext=sprintf("%dx%d+%d+%d",$w,$marg,0,0);
$geo=sprintf("%dx%d+%d+%d",$marg,$h,0,0);
$res=$im2->Composite(image=>$im,compose=>Over,extract=>$ext,rotate=>90,translate=>"$marg,0");
I haven't used the PerlMagick bindings for years, but I imagine you would want to create each of your 4 edge strips and then use +append to lay them out horizontally, side-by-side. Here's a crude example, just in Terminal:
magick -size 20x50 xc:red xc:lime xc:blue +append result.png
More specifically addressing your question, and starting with this image:
that would look like this:
#!/bin/bash
magick ~/sample/images/blocks-RGB.png -resize 100x100 +repage -write MPR:orig +delete \
\( MPR:orig -gravity northwest -crop 30x+0+0 \) \
\( MPR:orig -gravity northwest -crop x30+0+0 -rotate 90 \) \
\( MPR:orig -gravity southwest -crop x30+0+0 -rotate 90 \) \
\( MPR:orig -gravity northeast -crop 30x+0+0 \) \
+append result.png
Hopefully you can see the parallels with PerlMagick. The first line creates a copy of the image to work with, the second line crops the left edge, the third line crops the top edge, the fourth line crops the bottom edge, the fifth line crops the right edge and the last line appends the four cropped pieces side-by-side.
When I try to draw text using imagemagick compound letters show as splitted. For example the word ഉത്തരം shows as ഉത് തരം without space in it.
PS: I can't write here without space as it will show as normal compound letter.
My Sublime text editor also have this problem. But in Visual studio code, it works correctly. The commands I tried below:
magick -size 1040x1310 gradient:tomato-steelblue -font Meera -pointsize 50 -fill white -gravity center -bordercolor White -border 20x20 -draw "text 0,0 'ഉത്തരം'" image.png
magick -size 1040x1310 gradient:tomato-steelblue -font Meera -pointsize 50 -fill white -gravity center -bordercolor White -border 20x20 caption:'ഉത്തരം' image.png
magick -size 1040x1310 gradient:tomato-steelblue -font Meera -pointsize 50 -fill white -gravity center -bordercolor White -border 20x20 label:'ഉത്തരം' image.png
Version: ImageMagick 7.0.10-28 Q16 x86_64
Platform: Ubuntu
Previously I was using IM version 6 of 2017 build, now I upgraded to latest manually. Still convert --version shows 6 but magick --version and magick convert --version shows latest. I also tried above commands with magick convert.
Using ImageMagick 6.9.11.28 Q16 Mac OSX Sierra, the following label: command works just fine for me.
Perhaps your problem is the meera font you are using. I got mine from https://www.malayalamfont.com/download.php?id=867. Also check your version of freetype to be sure it is current. My version was 2.10.1
convert -size 100x -background white -font /Library/fonts/meera.ttf -fill black label:"ഉത്തരം" result.png
Also -annotate and -draw work:
convert -size 100x31 xc:white -gravity center -pointsize 28 -font /Library/fonts/meera.ttf -fill black -annotate +0+0 "ഉത്തരം" result.png
convert -size 100x31 xc:white -gravity center -pointsize 28 -font /Library/fonts/meera.ttf -fill black -draw "text 0,0 'ഉത്തരം'" result.png
I looked up how to type Option+0D09 Option+0D24 Option+0D4D Option+0D24 Option+0D30 Option+0D02 in my text editor. But what I get in the editor is not ഉത്തരം. It seems that pasting into this box changes what one sees.
What I see in my text editor is the same as what I get when I render it in ImageMagick. Are you sure your 3rd character set of code, Option+0D4D, is correct? I can verify that the utf codes are what I see in my text editor by looking them up using UnicodeChecker (for Mac). I note that these are UTF-16 characters.
convert -size 100x -background white -font /Library/fonts/Meera-Regular.ttf -fill black label:"ഉത്തരം" x1.png
Or saving what I type in my text editor to a file then doing:
convert -size 100x -background white -font /Library/fonts/Meera-Regular.ttf -fill black label:#hindi.txt x2.png
ADDITION:
Here are the glyphs for the UTF character codes you specified. These are exactly what I get from ImageMagick as above.
0D09:
0D24:
0D4D:
I got this working code for tiling an image in ImageMagick:
convert D:\tile.jpg -resize 300x300 -write mpr:tiler +delete ^
-size 900x900 tile:mpr:tiler -sharpen 0x2 D:\tiles.jpg
But now i found out that i need to add watermark in the same process. I got this working code for that:
tiles.jpg Wartermark.png -gravity southeast -geometry +0+0 -composite D:\tile-watermark.jpg
But how do i process those two in one line?
I recently started working with Imagemagick and I had a problem that needs to be solved.
I have such a thumbnail.
And there is such a mask.
I need to get this image on the output.
I looked through this link http://www.imagemagick.org/Usage/thumbnails/ I tried everything there, but I did not get success ((
I hope you will help me.
This should give you a result very much like your example...
convert mask.png image.png -gravity north -composite \
mask.png -compose copyopacity -composite result.png
You can adjust the positioning of the overlay by including something like "-geometry -10+0" before the first composite.
To use this command in Windows you'll need to change that continued line backslash "\" to a caret "^".
In Imagemagick, you should extract the alpha channel of your mask and put that into the alpha channel of your other image. So try
(unix syntax)
convert KlQZ6.png \( 7k9a9.png -alpha extract \) -alpha off -compose copy_opacity -composite result.png
(windows syntax)
convert KlQZ6.png ( 7k9a9.png -alpha extract ) -alpha off -compose copy_opacity -composite result.png
I have switch from Imagick version 5 to Imagick version 6 and noticed the following
While using the command:
convert -gravity SouthEast -draw 'image Over 0,0 0,0 overlay.png'
In version 5 the overlay.png is being added the bottom right corner (SouthEast) as expected!
But version 6 of ImageMagick failed and the position of the overlay.png is at the top left corner!
The command is used in typo3 "imgResource.params" http://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Imgresource/Index.html
But I think this has nothing to do with the CMS, but with compatibility of im5 and im6
Anyone knows how to solve this...?
You can use this command instead:
convert background.jpg foreground.jpg -gravity SouthEast -compose Src_Over -composite output.jpg
So if this is our background:
and this is our foreground:
we get the following result:
Actually, I think he looks better on the other side of the image, but flopped to still face inwards :-)
convert background.jpg \( tiger.png -flop \) -gravity SouthWest -compose Src_Over -composite out.jpg
Updated Answer
Sorry to hear that the command doesn't work inside typo3. There is another version here that may work for you...
First get the width and height of the background and foreground images - I guess there is a way to do this in typo3, but I'll do it like this:
identify -format "%w %h" background.jpg
906 603
So the background is 906 px wide and 603 px high, and
identify -format "%w %h" tiger.png
258 296
the tiger is 258 px by 296. Then we can overlay using geometry like this, by subtracting the width and height of tiger from the width and height of the background to give an offset from top left of image:
convert background.jpg tiger.png -geometry +648+307 -composite out.png
which gives the same effect as gravity southeast. Maybe that will get you there...
Updated One Last Time
This one must get you there... just put the correct offsets in your original draw command rather than relying on gravity. So the first two numbers are the x,y offsets of the top left corner of the overlaid image from the top left corner of the background image, and the second x,y pair are the offsets of the bottom right corner of the overlaid image. So basically,
x1,y1 = width background - width overlay, height background - height overlay
x2,y2 = width background, height background
convert background.jpg -draw 'image Over 648,307 906,603 tiger.png' out.jpg