PHP ImageMagick Plane2Cylinder透视图

bvjveswy  于 2023-03-21  发布在  PHP
关注(0)|答案(3)|浏览(168)

我试图通过PHP在ImageMagick中改变Plane 2Cylinder扭曲的Angular 。
为了帮助解释我在寻找什么,我创建了这个图形:

您可以看到红色块的下部比顶部具有更大的半径,就好像您是从上方中心查看此。
我尝试了可选的center_x/y字段:

  1. $label->distortImage(\Imagick::DISTORTION_PLANE2CYLINDER, [28,0,100], true);

在每个x和y上具有0到1000之间的各种设置,结果为零。
有没有人有什么见解或提示?我已经彻底搜索,但找不到任何相关的。

k5ifujac

k5ifujac1#

我还没有找到解决方案与扭曲_PLANE2CYLINDER,但只是作为一个想法,一个铁杆的Angular 可能会减少强度的差异,并可能成为一个点,为进一步扭曲,例如。圆形和径向扭曲方法(弧)。

  1. convert img.png \
  2. -matte \
  3. -virtual-pixel transparent \
  4. -distort Perspective '200,0,0,0 100,700,100,700 700,700,700,700 600,0,800,0 ' \
  5. img1.png

可以给予你想要的半径在顶部和底部。

piok6c0g

piok6c0g2#

编程解决方案

我用下面的代码解决了这个问题-工作起来像一个魅力,并提供了正确的结果。要知道,Angular 还取决于观看者的距离,而不仅仅是眼睛的水平。

  1. public function renderCyclinderToPlane()
  2. {
  3. //http://www.imagemagick.org/Usage/distorts/#cylinder2plane
  4. $imagick = new \Imagick(realpath($this->distortImageControl->getImagePath()));
  5. $points = array(
  6. 70, //fov_angle,
  7. //center_x,y,
  8. //fov_output,
  9. //dest_center_x,y
  10. );
  11. $imagick->setImageBackgroundColor("#fad888");
  12. $imagick->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_BACKGROUND);
  13. $imagick->distortImage(\Imagick::DISTORTION_CYLINDER2PLANE, $points, true);
  14. header("Content-Type: image/jpeg");
  15. echo $imagick;
  16. }

参考/学分转到:

另请参阅:如何在svg图像上应用枕形失真效果(以便可靠地读取圆形表面上的二维码)?

非编程替代

如果你只是想在玻璃杯/jar/瓶子上贴一个二维码,把它放在顶部或底部。

展开查看全部
pxq42qpu

pxq42qpu3#

所以,在所有这些工作试图弄清楚如何使用面具,过滤器等来做到这一点之后...解决方案实际上非常简单。
我最终只是将主图像放在一个更高的透明图像的顶部(从顶部向下正确的距离以创建透视图),然后将plane 2cylindar应用于整个图像。
太疯狂了,我没有看到开始。谢谢你的想法和帮助。
编辑-关于如何实现这一点的更多细节。

  1. $finalimage = new Imagick ('flowers_with_perspective.jpg'); // The final image
  2. // a canvas with no background that sets the foundation for the perspective I want.
  3. $canvas = new Imagick ();
  4. $canvas ->newImage ($width, $height+200, 'none'); // $height should be the input file size plus a bunch of extra height (200px for example).
  5. // the image I am want in perspective (the flowers in my example)
  6. $image = new Imagick ('flowers.jpg');
  7. $image->setImageBackgroundColor(new \ImagickPixel('transparent'));
  8. $image->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT); // make sure it's in transparent mode so when I overlay it on another image it doesn't have an odd background
  9. // get vertical offset for $image on $canvans
  10. $top = (($canvas->getImageHeight() - $image->getImageHeight())/2) +100; // should offset flower image 100px down from center
  11. // apply $image to $canvas at 0px left and $top px down from top
  12. $canvas->compositeImage ($image, Imagick::COMPOSITE_DEFAULT, 0, $top);
  13. // at this point we just have the normal 'flowers.jpg' but displayed 100px down from center on a larger, transparent canvas.
  14. // now apply plane2cylendar to create perspective on entire image
  15. $canvas->distortImage(\Imagick::DISTORTION_PLANE2CYLINDER, [26], true);
  16. // now you would apply the canvas to $finalimage along with other filters/overlays/etc you'd need and save!
展开查看全部

相关问题