5/2/2023 0 Comments Php imagemagick![]() ![]() You have to install a version of Imagick on your system that matches the PHP extension version.Īs others have instructed, download the latest PECL package for imagick for your PHP version. You can't used the latest Imagick (version 7 at the time of writing this) if you want to use the PHP extension, until the extension is upgraded. Luckily, all that is necessary is the latest PECL package and the corresponding version of Imagick for your system, which was the tricky part. At first I was copying DLLs all over the place like all of the instructions have you do. I am so cutting edge as to be using PHP 7.1 at the moment. This final example tiles text over the entire image which makes it far more difficult to remove.There are a lot of answers out there, as the landscape for this program and PHP have changed over time. To get around this foolish behavior, I’ve created my palettes with the same dimensions as the source image so no clipping takes place. This basically means that if I were to clip the edges then my watermark would lose its place at the bottom right and be re-positioned in the top-left corner. In the command-line version of the code, the outside edges of the transparent image are clipped before the watermark is overlayed, but there appears to be a bug that prevents the compositeImage() method from preserving the position defined by setGravity(). When I apply the mask by combining the images, any grey shades found in $mask as a result of anti-aliasing will be semi-transparent and result in smoother edges. The first image $watermark is grey-scale, and the second image $mask uses pure black for the parts I want to be transparent and white for the parts I want to keep. Several images are created in this example. $image->compositeImage($watermark, Imagick::COMPOSITE_DISSOLVE, 0, 0) $watermark->compositeImage($mask, Imagick::COMPOSITE_COPYOPACITY, 0, 0) $watermark->annotateImage($draw, 10, 12, 0, $text) Position text at the bottom right of the image $mask->newImage($width, $height, new ImagickPixel('black')) $watermark->newImage($width, $height, new ImagickPixel('gre圓0')) gravity center -draw "fill grey70 text 0,0 'Copyright'"Ĭonvert -size 300x50 xc:black -font Arial -pointsize 20 -gravity centerĬomposite -compose CopyOpacity mask.png fgnd.png stamp.pngĬomposite -gravity south -geometry +0+10 stamp.png image.png But while this works, the text stands out too drastically from the image and the effect should probably be more subtle.įor a smoother effect on the watermark text, you can make the text string transparent using a font mask.Ĭommand line example: convert -size 300x50 xc:gre圓0 -font Arial -pointsize 20 ![]() This example is pretty straight-forward and the code’s comments make it so you shouldn’t need much extra explanation. Draw text again slightly offset with a different color $draw->setGravity(Imagick::GRAVITY_SOUTHEAST) Position text at the bottom-right of the image ![]() The command line example is: convert image.png -font Arial -pointsize 20Īnd the PHP equivalent is: setFont('Arial') The easiest type of textual watermark to create is a string overlay on top of the image. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |