I been working all day to add shadow to text using command line imagemagick. Googled many pages and experimented with gaussian, blur, shadow commands for dropping shadow but no success.
Here is my command in php:
$img_save = 'C:\Users\abc\Desktop\testimage.jpg';
$line = "Anatidaephobia is the fear that somewhere in the world there is a duck watching you. ";
$line = wordwrap($line, 25, "\\n");
exec("convert -background white -weight bold -size 500x -pointsize 35 -font arial-italic -gravity center -fill black caption:\"$line\" $img_save");
The above code gives image without difficulty. Can anyone tell how to add shadow to text in the image?
Thanks
With caption just clone and shadow it with,
convert logo: -resize 40%x40 \
\( -size "80x40" -background none -gravity west \
-fill green caption:"Caption text" \
\( +clone -background navy -shadow 80x3+5+5 \) \
+swap -background none -layers merge +repage \) -composite out.png
You just have to draw the shadow first then draw over it with the font
convert -size 500x500 xc:white -pointsize 35 -font arial-italic -gravity center - fill red -draw "text 2,2 'text'" -fill black -draw "text 0,0 'text'" outfile.jpg
Related
I am outputting a banner with an image to the left and some text to the right. This is working well, however the positioning is very manual. I'd like to be able to group the $robot_image and the $robot_name text into one image, and then center that image group on the background 1400x500 canvas. Any ideas how I'd achieve this? The attached image is what I'd like to achieve: The robot + text centered as a group on the canvas
$banner = exec("convert {$robot_image} -resize 500x500 -gravity west -geometry +100+100 -background '#{$hex}' -extent 1400x500 -font 'SignPainter.ttc' -pointsize 300 -fill 'white' -strokewidth 20 -fill white \
-stroke 'rgba(0,0,0,0.3)' -annotate +550+40 '{$robot_name}' \
-stroke none -annotate +550+40 '{$robot_name}' output.jpg");
For anyone interested, this is how I achieved it:
convert robot.png -resize 500x500 -background "#31BEFF" -size 600x -font 'SignPainter.ttf' -gravity center label:"RobotName" -alpha off +smush -50 -gravity center -background "#31BEFF" -extent 1400x500 result.jpg
I am attempting to write an imagemagick command to trim the transparent pixels from the bottom of a transparent PNG. I found these commands and modified them to take off just the bottom. However the output is not as expected.
With some trial and error I've identified that the command appears to be generating an image of a minimum height. If the design is too high it leaves transparent pixels underneath. But nothing jumps out at me as being the element of the command that causes that?
I've included my 3 files that I trimmed and the 3 results that the following command(s)
generates:
convert \( ORIGINAL.png -bordercolor none -border 1x0 \) -size 1x1 xc:black -gravity west -composite -size 1x1 xc:black -gravity east -composite -size 1x1 xc:black -gravity north -composite -fuzz 10% -trim +repage -bordercolor white -shave 1x0 TRIMMED.png
convert \( ORIGINAL2.png -bordercolor none -border 1x0 \) -size 1x1 xc:black -gravity west -composite -size 1x1 xc:black -gravity east -composite -size 1x1 xc:black -gravity north -composite -fuzz 10% -trim +repage -bordercolor white -shave 1x0 TRIMMED2.png
convert \( ORIGINAL3.png -bordercolor none -border 1x0 \) -size 1x1 xc:black -gravity west -composite -size 1x1 xc:black -gravity east -composite -size 1x1 xc:black -gravity north -composite -fuzz 10% -trim +repage -bordercolor white -shave 1x0 TRIMMED3.png
If someone could please explain what I am missing in terms of this height issue that would be really appreciated.
These are the 3 ORIGINAL files and the 3 outcomes showing how the outcome changes with the original file changes.
This is what I am trying to acheive - delete the empty space from the bottom of the image. I want no space after the image at the moment if it is too high I still get space underneath (see the last outcome, bottom right)
---- BELOW ARE JUST THE ORIGINAL FILES IF ANYONE WANTED TO TRY IT ON THEIR SETUP ETC ----
If you're trying to remove what a "-trim" would remove, but only from the bottom edge of an image, this command should give you that result...
convert input.png -background none -set page %[#] \
-set option:distort:viewport %[w]x%[fx:page.y+page.height] \
+repage -distort SRT 0 result.png
It starts by setting some variables that contain the results of a "-trim" operation, but without actually removing anything. Then it uses those variables to calculate the after-trim dimensions for the output viewport. Then it uses a no-op "-distort" to effectively crop the image to the calculated output dimensions, removing only the excess transparent pixels toward the bottom.
I need to be able to write some text automatically inside an image. According to the image lightness, the script must write in white or black.
So how do I check the lightness/darkness of an image with Imagick?
You could do something like this:
// Load the image
$imagick = new Imagick("image.jpg");
// convert to HSL - Hue, Saturation and LIGHTNESS
$imagick->transformImageColorspace(imagick::COLORSPACE_HSL);
// Get statistics for the LIGHTNESS
$Lchannel = $imagick->getImageChannelMean(imagick::CHANNEL_BLUE);
$meanLightness = $Lchannel['mean']/65535;
printf("Mean lightness: %f",$meanLightness);
If you want to do undercoloured text, per Fred's suggestion, you can do that in PHP with:
$image = new Imagick("image.jpg");
$draw = new ImagickDraw();
$draw->setFillColor('#ffffff');
$draw->setFontSize(24);
$draw->setTextUnderColor('#ff000080');
$image->annotateImage($draw,30,50,0,"Undercoloured Text");
$image->writeImage('result.jpg');
You could also just create a text image on some background color and overlay that on the image. Or use -undercolor with -draw or -annotate. That way, you do not have to worry about the color of the image. Or you could specify the region where you want to write text over, then get the average lightness of that region. Then test if the region is brighter or darker than mid-gray. If brighter, then create a text image of the same size with transparent background and use black text color. Similarly if darker, use white text color. So in ImageMagick command line, these would be:
Input:
Pink Undercolor:
convert logo.png \
\( -size 110x -background pink -font ubuntu-bold -fill $textcolor label:"Testng" \) \
-gravity northwest -geometry +395+400 -compose over -composite result3.png
Testing (dark region) - Unix syntax:
test=`convert logo.png -crop 110x36+395+400 +repage -colorspace gray -format "%[fx:(mean>0.5)?1:0]" info:`
if [ $test -eq 1 ]; then
textcolor="black"
else
textcolor="white"
fi
convert logo.png \
\( -size 110x -background none -font ubuntu-bold -fill $textcolor label:"Testng" \) \
-gravity northwest -geometry +395+400 -compose over -composite result1.png
Testing (bright region):
test=`convert logo.png -crop 110x36+100+400 +repage -colorspace gray -format "%[fx:(mean>0.5)?1:0]" info:`
if [ $test -eq 1 ]; then
textcolor="black"
else
textcolor="white"
fi
convert logo.png \
\( -size 110x -background none -font ubuntu-bold -fill $textcolor label:"Testng" \) \
-gravity northwest -geometry +100+400 -compose over -composite result2.png
Sorry, I do not know Imagick. So someone else may need to help on that.
I recently tried imagemagick and wanted to ask how I create an image (.bmp file) which looks like this:
My current code looks like this:
convert -size 720x480 xc:blue \ -fill white -stroke black -strokewidth 0 -draw "line 5,20 95,20" \ myImage.bmp
But it creates this
I would probably go with this:
convert xc:black[720x480\!] -size 100x5 \
\( xc:lime xc:blue -append -write MPR:stripe \) -geometry +165+400 -composite \
MPR:stripe -geometry +295+400 -composite \
MPR:stripe -geometry +425+400 -composite result.png
The interesting part is the second line where I create a lime green rectangle and a blue one the same size underneath (-append) and save that in an MPR (Magick Persistent Register) called stripe, then I re-use that to make each subsequent stripe.
Or this:
convert -size 720x480 xc:black -strokewidth 5 \
-stroke lime \
-draw "line 165,400 265,400" -draw "line 295,400 395,400" -draw "line 425,400 525,400" \
-stroke blue \
-draw "line 165,405 265,405" -draw "line 295,405 395,405" -draw "line 425,405 525,405" myImage.bmp
You have some rubbish in your command but it has done what you asked it to - draw a black line on a blue background.
This should get you started:
convert -size 720x480 xc:black -strokewidth 5 -stroke green -fill none -draw "line 50,200 95,200" -stroke blue -draw "line 50,205 95,205" myImage.bmp
I have a 424x318 image that I "draw" a circle into and leave the rest transparent. I want to then take that circle and crop it out. How can I do this?
My function (the bash variables are just the normal stuff, $SCALEFILE is the file, $NEWFILE is what it saves it as and $SIZE is just the normal size string x0,y0 x1,y1)
convert -size 416x318 xc:none -fill $SCALEFILE -draw "circle $SIZE" $NEWFILE
ps. my circle dimensions change.
Thanks!
You can use -crop WxH+X+Y +repage to crop to the circle.
For example:
convert -size 300x300 xc:transparent -fill "image.png" -draw "circle 240,90 290,90" -crop 100x100+190+40 +repage circle1.png
convert -size 300x300 xc:transparent -fill "image.png" -draw "circle 70,90 110,90" -crop 100x100+20+40 +repage circle2.png