简体   繁体   中英

Imagemagick convert from PHP, to draw 2 borders on image

I would like to take a simple image file (500px width example) from a folder, in PHP and do exec('/usr/bin/convert -etc.') to the image and achieve this: http://imm.io/media/3O/3O7j.jpg . Basically, I want to draw 2 colored borders/rectangles around the image at that specific positions. Can anybody help compose such a command, or is it possible ?

Thank you.

This may be easier using the GD extension in PHP. Specifically, the imagesetstyle() function to set line dashes, and imageline() to draw the lines.

This example loads an image and draws a dashed line on it. You should be able to adapt it to your needs.

<?php
$im  = imagecreatefromjpeg('/your/file.jpg');
$w   = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);

/* Draw a dashed line, 5 red pixels, 5 white pixels */
$style = array($red, $red, $red, $red, $red, $w, $w, $w, $w, $w);
imagesetstyle($im, $style);
imageline($im, 0, 0, 100, 100, IMG_COLOR_STYLED);

imagejpeg($im, '/path/to/save.jpg');
imagedestroy($im);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM