【问题标题】:How to apply pagecurl effect on a static image by PHP如何通过 PHP 对静态图像应用 pagecurl 效果
【发布时间】:2015-06-02 05:53:27
【问题描述】:

我想使用 PHP 和 ImageMagick 对图像应用卷曲或剥离效果。

我在 PHP 中尝试了各种库,但只有 ImageMagick 可以这样做。我想要和这里一样的输出:

【问题讨论】:

    标签: php imagemagick page-curl


    【解决方案1】:

    在 Fred Weinhaus 的高级 ImageMagick 脚本集合中,有 pagecurl 脚本。

    开箱即用,它在 IM 内置 wizard: 测试图像上创建以下效果:

     pagecurl  wizard:  wiz-curled.png
    

    脚本将效果应用于右下角,但可以通过多种方式对其进行参数化:

     pagecurl:
    
     USAGE: pagecurl [-a amount] [-m mode] [-c color] [-b bgcolor] [-e ellipticity] [-x xcoord] [-y ycoord] [-g gcontrast] [-d dcontrast] infile [bgfile] outfile 
     USAGE: pagecurl [-help]
    
     OPTIONS:
    
     -a      amount            amount of pagecurl expressed as percent of image 
                               width; integer>=0; default=50
     -m      mode              mode of shading curl; plain, grad or doublegrad; 
                               default=grad
     -c      color             color to apply to curl; any valid IM color; 
                               default=white
     -b      bgcolor           background color to apply to image where curled away;
                               any valid IM color; default=none (transparent)
     -e      ellipticity       curl flattening from circle to ellipse; 
                               0<=float<1; default=0 for circle; recommended value 
                               other 0 is 0.5 for ellipse shape 
     -x      xcoord            x coordinate for apex of curl; 
                               default=right image edge
     -y      ycoord            y coordinate for apex of curl; 
                               default=upper image edge
     -g      gcontrast         contrast adjustment for mode=grad; 0<=integer<=100; 
                               increases contrast only; default=15
     -d      dcontrast         contrast adjustment for mode=doublegrad; 
                               -100<=integer<=100; positive increase contrast; 
                               negative decreases contrast; default=0
    
    
     NAME: PAGECURL 
    
     PURPOSE: Applies a pagecurl effect to the lower right corner of an image.
    
     DESCRIPTION: PAGECURL Applies a pagecurl effect to the lower right corner 
     of an image. The apex of the curl is nominally in the upper right corner of 
     the image, but can be adjusted. The curl is always right to left. The curl 
     can be shaded and/or colored. The removed area can be colored, transparent 
     or filled with an optional same size background image if provided. Note 
     that this is a 2D simulation and not a true 3D effect.
    
    
     OPTIONS: 
    
     -a amount ... AMOUNT of pagecurl expressed as percent of image width. 
                   Values are in range integer>=0. The default=50.
                   Caution: values below about 5 may fail.
    
     -m mode ... MODE shading on the curl.
                 Choices are: plain (or p), grad (or g) for gradient, or 
                 doublegrad (or d) for double gradient. Default=grad.
    
     -c color ... COLOR is the color to apply to curl.
                  Any valid IM color is allowed. The default=white.
    
     -b bgcolor ... BGCOLOR is the color to apply to curled away part of the image. 
                    Any valid IM color is allowed. The default=none for transparent.
                    If a background file is provided, bgcolor must be none.
    
     -e ellipticity ... ELLIPTICITY is the amount of curl flattening from a circle 
                        to an ellipse.
                        Values are in range 0<=float<1. The default=0 for circle. 
                        Recommended value other 0 is 0.5 for ellipse shape. 
    
     -x xcoord ... XCOORD is the X coordinate for the apex of the curl.
                   Values are 0<integers<width.
                   The default is the right edge of the image.
    
     -y ycoord ... YCOORD is the Y coordinate for the apex of the curl.
                   Values are integers.
                   The default is the upper edge of the image.
    
     -g gcontrast ... GCONTRAST is the contrast adjustment for mode=grad.
                      Values are in range 0<=integer<=100.
                      This increases contrast only. The default=15
    
     -d dcontrast ... DCONTRAST is the contrast adjustment for mode=doublegrad. 
                      Values are in range -100<=integer<=100.
                      Positive values increase contrast. 
                      Negative values decrease contrast. The default=0
    
     Thanks to Anthony Thyssen for critiqing the original version and for 
     several useful suggestions for improvement.
    
     CAVEAT: No guarantee that this script will work on all platforms, 
     nor that trapping of inconsistent parameters is complete and 
     foolproof. Use At Your Own Risk. 
    

    要获得右上角的卷曲效果,您可以执行以下操作:

    convert wizard: -flip -frame 1 miff:- \
    | pagecurl -a 15 -m grad -e 0.5 -y 510 -x 479 -c lightgray -g 33 - miff:- \
    | convert - -flip curl2.png
    
    convert wizard: -flip -frame 1 miff:- \
    | pagecurl -a 20 -m grad -e 0.7 -y 490 -x 479 -c lightgray -g 5 - miff:- \
    | convert - -flip curl3.png
    

    那么结果是这样的:

    【讨论】:

    • 感谢 Kurt Pfeifle 的回答,但我想要 php 核心中的示例。它是基于 linux 的命令并且可以工作,但我需要基于 wamp 的服务器。
    • 您在原始问题中没有提到 WAMP 或 Windows。命令行可以很容易地翻译以便在 PHP 中重复使用。将他的pagecurl shell 脚本转换为 Windows .bat 文件更具挑战性,但也可以完成。
    • 要让脚本把卷曲放在右上角,首先要垂直翻转图像。然后运行脚本。然后垂直翻转输出。如果你有 Cygwin 或 Windows 10 unix 等 unix 环境,该脚本可以在 Windows 中运行。
    【解决方案2】:

    我会使用覆盖图像(可能是带有 alpha 的 PNG)应用此效果 - 这可以使用 ImageMagick 或在渲染层(例如 HTML/CSS 等)中完成

    对于 PHP/Imagick 扩展,Imagick::mergeImageLayers 方法可能有用。

    【讨论】:

    • 最后我在 imagemagick libray 中使用 -flatten 命令得到了解决方案
    猜你喜欢
    • 2014-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 2010-12-29
    • 2023-04-03
    • 2012-08-11
    相关资源
    最近更新 更多