简体   繁体   English

将Imagemagick从PHP转换为在图像上绘制2个边框

[英]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 . 我想从PHP的文件夹中提取一个简单的图像文件(例如500px宽度),然后对图像执行exec('/ usr / bin / convert -etc。')并实现此目标: http ://imm.io /media/3O/3O7j.jpg Basically, I want to draw 2 colored borders/rectangles around the image at that specific positions. 基本上,我想在该特定位置的图像周围绘制2个彩色边框/矩形。 Can anybody help compose such a command, or is it possible ? 任何人都可以帮助编写这样的命令吗,或者可能吗?

Thank you. 谢谢。

This may be easier using the GD extension in PHP. 使用PHP中的GD扩展可能会更容易。 Specifically, the imagesetstyle() function to set line dashes, and imageline() to draw the lines. 具体来说, imagesetstyle()函数用于设置线破折号,而imageline()函数用于绘制线。

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);
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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