php,unix command ,imagick help me - php

This command add the text "flower" to the image:
convert flower.jpg -font courier -fill white -pointsize 20 -annotate +50+50 'Flower' flower_annotate1.jpg
I'm using ImageMagick 2.2.0. I'm running it from PHP using:
system('convert flower.jpg -font courier -fill white -pointsize 20 -annotate +50+50 'Flower' flower_annotate1.jpg');
but I'm not getting the result

Escape the single-quotes in the parameters:
system('convert flower.jpg -font courier -fill white -pointsize 20 -annotate +50+50 \'Flower\' flower_annotate1.jpg');
Or just wrap the thing in double-quotes so you don't have to escape them.

Related

ImageMagick center image group on canvas

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

imagemagick trim the bottom from transparent PNG

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.

ImageMagick create image with 2 lines

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

Shadow text with ImageMagick

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

Transparent PNG imagemagick passthru

I have this code. It should crate a transparent PNG, but its output is black backgrounded PNG instead. On CentOS.
<?php
header( 'Content-Type: image/png' );
passthru("convert -background transparent -fill red -pointsize 72 -font TR.Matisse.ITC.TTF -gravity Center label:'Font Test' png:-");
?>
this works flawlessly on ubuntu terminal:
convert -background transparent -fill red -pointsize 72 -font TR.Matisse.ITC.TTF -gravity Center label:'Font Test' png.png
So how do I get it to be transparent (and not have a black matte) by calling the system command from PHP?
Isn't the proper transparent command for ImageMagick this:
convert -transparent <SomeColor> -fill red -pointsize 72 -font TR.Matisse.ITC.TTF -gravity Center label:'Font Test' png.png
Or else use an Alpha channel:
convert -alpha transparent -fill red -pointsize 72 -font TR.Matisse.ITC.TTF -gravity Center label:'Font Test' png.png
Try using exec() and saving the file to disk then see if it is the correct image. You may find the issue is with php and the passthru.

Categories