PHP Imagick大纲/轮廓和草图 [英] PHP Imagick outline/contour and sketch

查看:215
本文介绍了PHP Imagick大纲/轮廓和草图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题就是获得精细的图像轮廓

I have a problem with getting fine contour of the image.

如何使用PHP Imagick进行操作?

输入图片: Imagick向导


  1. 获取图像(更多/更少)清晰,一致的背景(例如:白色,红色或透明)

  2. 删除背景(如果已设置)

  3. 添加大纲(特定颜色)

  4. 删除里面的图片

  1. Get image with (more/less) clear, consistent background (for example: white, red or transparent)
  2. Remove background if it is set
  3. Add outline (specific color)
  4. Remove image inside

结果:

Result: http://i57.tinypic.com/2wg91qx.png


  1. 获取图像(更多/更少)清晰,一致的背景(例如:白色,红色或透明)

  2. 删除背景(如果已设置)

  3. 添加草图效果

  4. 删除图像

  1. Get image with (more/less) clear, consistent background (for example: white, red or transparent)
  2. Remove background if it is set
  3. Add sketch effect
  4. Remove image inside

结果: http://i60.tinypic .com / az9vr5.png

PS:
border和/或阴影不适合我

PS: borders and/or shadows didnt' work for me well

推荐答案

有很多方法可以勾勒出一幅画面。这是其中一个或多或少地做你想要的东西。请注意,向导的图片需要一些额外的处理。第一个背景不是完全白色的(它有一些#FEFEFE或类似的像素)。更令人不安的是桌子的上半部分充满了纯白色。因此,您可以在模糊后使用白色像素作为背景(我的方式)或尝试使用 matteFloodfillImage()从角落填充填充。然而,这可能会使桌腿之间的空间不透明。

There are many ways to outline a picture. Here's one of them that does more or less what you wanted. Note that wizard's picture requires some extra processing. First background isn't fully white (it has some #FEFEFE or alike pixels). Also what is more troubling the upper part of the desk is filled with pure white. So you can either use white pixels after blurring as background (my way) or try to flood fill from the corner with matteFloodfillImage(). However this may leave space between desk legs not transparent.

function drawImage(Imagick $i) 
{
    $i->setImageFormat("png");
    header("Content-Type: image/" . $i->getImageFormat());
    echo $i;
    exit;
}

$o = new Imagick('wizard.png');
$o->setImageBackgroundColor('white'); // handle tranparent images
$o = $o->flattenImages(); // flatten after setting background
$o->blurImage(5, 30);
$o->whiteThresholdImage( "#F8F8F8" );
$o->blackThresholdImage( "#FFFFFF" );
$o->edgeImage(5);
$o->negateImage(false);
$o->paintTransparentImage($o->getImagePixelColor(0, 0), 0, 2000);
$o->colorizeImage("red", 1);

drawImage($o);

素描有点复杂,我建议进一步阅读IM功能 http://www.imagemagick.org/Usage/photos/#color-in

Sketching is a little more complex and I would recommend further reading on IM capabilities http://www.imagemagick.org/Usage/photos/#color-in

这篇关于PHP Imagick大纲/轮廓和草图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆