dpl74687 2018-06-29 05:36
浏览 97

PHP和Imagemagick:将表格渲染为图像,但模糊了图像的下边缘

I'm looking for a PHP script that renders table data as image, but blurs out the content after, for example, the fifth row.

My example is from Wikipedia.

Some commercial websites / newspapers try to tease their customer by showing the preview of some data, but pixelate the lowest part of it.

Now I have to do such an unfair thing, too. Do you know any PHP library that already supports this? I wasn't able to figure out a good name for what I need, so it was difficult to find something good.

Thanks in advance.

pixelated

  • 写回答

1条回答 默认 最新

  • dsgw3315 2018-06-29 20:19
    关注

    You could create the table as you do now. Then use Imagick to blur everything after some y (line coordinate). Sorry I only know Imagemagick which is used by Imagick, not Imagick itself. Here is how I would do it in Imagemagick. I would blur the input image. Then I would create a mask image that was black above your desired line and white below it. Then I would composite the input, blurred image using the mask to get your desired results. I have taken your image above and processed it this way:

    Input: enter image description here

    bottomy=676
    wd=`convert image.png -format "%w" info:`
    ht=`convert image.png -format "%h" info:`
    convert image.png \( -clone 0 -blur 0x5 \) \( -size ${wd}x${bottomy} xc:black -background white -extent ${wd}x${ht} \) -composite result.png
    

    Result: enter image description here

    You can get the width and height of your input in PHP directly. Then use the Imagick blurImage() to blur a copy. See http://us3.php.net/manual/en/imagick.blurimage.php

    Then create the mask using newImage() for the black part http://us3.php.net/manual/en/imagick.newimage.php. Then use extendImage() for the white part. See http://us3.php.net/manual/en/imagick.extentimage.php

    Then do the composite. See http://us3.php.net/manual/en/imagick.compositeimage.php

    However, it looks like compositeImage() only allows two images. So you must create the mask and put it into the alpha channel of the blurred image. Then negate the mask and put it into the alpha channel of the input image. That can be done with compositeImage() using COMPOSITE_COPYOPACITY. Once you have that done, you can flattenImages() the two images together to make the output. See http://us3.php.net/manual/en/imagick.flattenimages.php

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100