此扩展最适合GraphicsMagick1.4+和PHP5.1.3+版本。Gmagick应该可以使用GraphicsMagick 1.2.6之前的早期版本,但这些版本不支持某些功能和格式。GraphicsMagick的Windows版本可从GraphicsMagick网站获得。
ImageMagick和GraphicsMagick之间的区别
GraphicsMagick最初基于ImageMagick2002年11月发布的ImageMagick5.5.2(派生自ImageMagickStudioLLC),而ImageMagickStudioLLC于1999年8月从E.I.DuPontDeNemours和Company1992年开发的ImageMagick派生自ImageMagick1999年8月。除了作为“gm”命令的子命令执行的实用程序外,命令行语法和编程api与ImageMagick 5.5.2保持完全向上兼容。一个更好的问题可能是“ImageMagick与ImageMagick有何不同?”因为ImageMagick继续改变和发展它的接口,所以它们不再与早期版本完全兼容。虽然GraphicsMagick还添加了新的特性,但它确实保证了现有特征的工作方式。ImageMagick专注于添加新的功能和特性,自fork以来已经发生了几次显著的变化。
GraphicsMagick维护一个稳定的发布分支,维护一个详细的变更日志,并维护一个具有完整版本历史记录的稳定源存储库,以便控制更改,并准确描述发布之间的更改。GraphicsMagick为发布分支提供持续支持。ImageMagick没有提供这些东西。
由于GraphicsMagick更加稳定,因此花了更多的时间优化和调试其代码。
GraphicsMagick比ImageMagick小得多,并且对外部库的依赖性大大降低。例如,在FreeBSD操作系统上,GraphicsMagick的全功能安装依赖于36个库,而ImageMagick需要64个库。GraphicsMagick的安装占用空间比ImageMagick小3-5倍。
GraphicsMagick通常比ImageMagick快。简单命令的基线执行开销要低得多,GraphicsMagick在处理大型图像时也更高效。
新的发行版本、下载、源文件、 维护人员信息及变更日志等,都在此处: https://pecl.php.net/package/gmagick.
范例
The following shows some common Gmagick image operations.
Example #1 Gmagick Example
<?php //Instantiate a new Gmagick object $image = new Gmagick('example.jpg'); //Make thumbnail from image loaded. 0 for either axes preserves aspect ratio $image->thumbnailimage(100, 0); //Create a border around the image, then simulate how the image will look like as an oil painting //Notice the chaining of mutator methods which is supported in gmagick $image->borderimage("yellow", 8, 8)->oilpaintimage(0.3); //Write the current image at the current state to a file $image->write('example_thumbnail.jpg'); ?>
Gmagick类
Gmagick { /* 方法 */ public addimage ( Gmagick $source ) : Gmagick public addnoiseimage ( int $noise_type ) : Gmagick public annotateimage ( GmagickDraw $GmagickDraw , float $x , float $y , float $angle , string $text ) : Gmagick public blurimage ( float $radius , float $sigma [, int $channel ] ) : Gmagick public borderimage ( GmagickPixel $color , int $width , int $height ) : Gmagick public charcoalimage ( float $radius , float $sigma ) : Gmagick public chopimage ( int $width , int $height , int $x , int $y ) : Gmagick public clear ( void ) : Gmagick public commentimage ( string $comment ) : Gmagick public compositeimage ( Gmagick $source , int $COMPOSE , int $x , int $y ) : Gmagick public __construct ([ string $filename ] ) public cropimage ( int $width , int $height , int $x , int $y ) : Gmagick public cropthumbnailimage ( int $width , int $height ) : Gmagick public current ( void ) : Gmagick public cyclecolormapimage ( int $displace ) : Gmagick public deconstructimages ( void ) : Gmagick public despeckleimage ( void ) : Gmagick public destroy ( void ) : bool public drawimage ( GmagickDraw $GmagickDraw ) : Gmagick public edgeimage ( float $radius ) : Gmagick public embossimage ( float $radius , float $sigma ) : Gmagick public enhanceimage ( void ) : Gmagick public equalizeimage ( void ) : Gmagick public flipimage ( void ) : Gmagick public flopimage ( void ) : Gmagick public frameimage ( GmagickPixel $color , int $width , int $height , int $inner_bevel , int $outer_bevel ) : Gmagick public gammaimage ( float $gamma ) : Gmagick public getcopyright ( void ) : string public getfilename ( void ) : string public getimagebackgroundcolor ( void ) : GmagickPixel public getimageblueprimary ( void ) : array public getimagebordercolor ( void ) : GmagickPixel public getimagechanneldepth ( int $channel_type ) : int public getimagecolors ( void ) : int public getimagecolorspace ( void ) : int public getimagecompose ( void ) : int public getimagedelay ( void ) : int public getimagedepth ( void ) : int public getimagedispose ( void ) : int public getimageextrema ( void ) : array public getimagefilename ( void ) : string public getimageformat ( void ) : string public getimagegamma ( void ) : float public getimagegreenprimary ( void ) : array public getimageheight ( void ) : int public getimagehistogram ( void ) : array public getimageindex ( void ) : int public getimageinterlacescheme ( void ) : int public getimageiterations ( void ) : int public getimagematte ( void ) : int public getimagemattecolor ( void ) : GmagickPixel public getimageprofile ( string $name ) : string public getimageredprimary ( void ) : array public getimagerenderingintent ( void ) : int public getimageresolution ( void ) : array public getimagescene ( void ) : int public getimagesignature ( void ) : string public getimagetype ( void ) : int public getimageunits ( void ) : int public getimagewhitepoint ( void ) : array public getimagewidth ( void ) : int public getpackagename ( void ) : string public getquantumdepth ( void ) : array public getreleasedate ( void ) : string public getsamplingfactors ( void ) : array public getsize ( void ) : array public getversion ( void ) : array public hasnextimage ( void ) : mixed public haspreviousimage ( void ) : mixed public implodeimage ( float $radius ) : mixed public labelimage ( string $label ) : mixed public levelimage ( float $blackPoint , float $gamma , float $whitePoint [, int $channel = Gmagick::CHANNEL_DEFAULT ] ) : mixed public magnifyimage ( void ) : mixed public mapimage ( gmagick $gmagick , bool $dither ) : Gmagick public medianfilterimage ( float $radius ) : void public minifyimage ( void ) : Gmagick public modulateimage ( float $brightness , float $saturation , float $hue ) : Gmagick public motionblurimage ( float $radius , float $sigma , float $angle ) : Gmagick public newimage ( int $width , int $height , string $background [, string $format ] ) : Gmagick public nextimage ( void ) : bool public normalizeimage ([ int $channel ] ) : Gmagick public oilpaintimage ( float $radius ) : Gmagick public previousimage ( void ) : bool public profileimage ( string $name , string $profile ) : Gmagick public quantizeimage ( int $numColors , int $colorspace , int $treeDepth , bool $dither , bool $measureError ) : Gmagick public quantizeimages ( int $numColors , int $colorspace , int $treeDepth , bool $dither , bool $measureError ) : Gmagick public queryfontmetrics ( GmagickDraw $draw , string $text ) : array public queryfonts ([ string $pattern = "*" ] ) : array public queryformats ([ string $pattern = "*" ] ) : array public radialblurimage ( float $angle [, int $channel = Gmagick::CHANNEL_DEFAULT ] ) : Gmagick public raiseimage ( int $width , int $height , int $x , int $y , bool $raise ) : Gmagick public read ( string $filename ) : Gmagick public readimage ( string $filename ) : Gmagick public readimageblob ( string $imageContents [, string $filename ] ) : Gmagick public readimagefile ( resource $fp [, string $filename ] ) : Gmagick public reducenoiseimage ( float $radius ) : Gmagick public removeimage ( void ) : Gmagick public removeimageprofile ( string $name ) : string public resampleimage ( float $xResolution , float $yResolution , int $filter , float $blur ) : Gmagick public resizeimage ( int $width , int $height , int $filter , float $blur [, bool $fit = FALSE ] ) : Gmagick public rollimage ( int $x , int $y ) : Gmagick public rotateimage ( mixed $color , float $degrees ) : Gmagick public scaleimage ( int $width , int $height [, bool $fit = FALSE ] ) : Gmagick public separateimagechannel ( int $channel ) : Gmagick setCompressionQuality ( int $quality = 75 ) : Gmagick public setfilename ( string $filename ) : Gmagick public setimagebackgroundcolor ( GmagickPixel $color ) : Gmagick public setimageblueprimary ( float $x , float $y ) : Gmagick public setimagebordercolor ( GmagickPixel $color ) : Gmagick public setimagechanneldepth ( int $channel , int $depth ) : Gmagick public setimagecolorspace ( int $colorspace ) : Gmagick public setimagecompose ( int $composite ) : Gmagick public setimagedelay ( int $delay ) : Gmagick public setimagedepth ( int $depth ) : Gmagick public setimagedispose ( int $disposeType ) : Gmagick public setimagefilename ( string $filename ) : Gmagick public setimageformat ( string $imageFormat ) : Gmagick public setimagegamma ( float $gamma ) : Gmagick public setimagegreenprimary ( float $x , float $y ) : Gmagick public setimageindex ( int $index ) : Gmagick public setimageinterlacescheme ( int $interlace ) : Gmagick public setimageiterations ( int $iterations ) : Gmagick public setimageprofile ( string $name , string $profile ) : Gmagick public setimageredprimary ( float $x , float $y ) : Gmagick public setimagerenderingintent ( int $rendering_intent ) : Gmagick public setimageresolution ( float $xResolution , float $yResolution ) : Gmagick public setimagescene ( int $scene ) : Gmagick public setimagetype ( int $imgType ) : Gmagick public setimageunits ( int $resolution ) : Gmagick public setimagewhitepoint ( float $x , float $y ) : Gmagick public setsamplingfactors ( array $factors ) : Gmagick public setsize ( int $columns , int $rows ) : Gmagick public shearimage ( mixed $color , float $xShear , float $yShear ) : Gmagick public solarizeimage ( int $threshold ) : Gmagick public spreadimage ( float $radius ) : Gmagick public stripimage ( void ) : Gmagick public swirlimage ( float $degrees ) : Gmagick public thumbnailimage ( int $width , int $height [, bool $fit = FALSE ] ) : Gmagick public trimimage ( float $fuzz ) : Gmagick public writeimage ( string $filename [, bool $all_frames = FALSE ] ) : Gmagick }
GmagickDraw类
GmagickDraw { /* 方法 */ public annotate ( float $x , float $y , string $text ) : GmagickDraw public arc ( float $sx , float $sy , float $ex , float $ey , float $sd , float $ed ) : GmagickDraw public bezier ( array $coordinate_array ) : GmagickDraw public ellipse ( float $ox , float $oy , float $rx , float $ry , float $start , float $end ) : GmagickDraw public getfillcolor ( void ) : GmagickPixel public getfillopacity ( void ) : float public getfont ( void ) : mixed public getfontsize ( void ) : float public getfontstyle ( void ) : int public getfontweight ( void ) : int public getstrokecolor ( void ) : GmagickPixel public getstrokeopacity ( void ) : float public getstrokewidth ( void ) : float public gettextdecoration ( void ) : int public gettextencoding ( void ) : mixed public line ( float $sx , float $sy , float $ex , float $ey ) : GmagickDraw public point ( float $x , float $y ) : GmagickDraw public polygon ( array $coordinates ) : GmagickDraw public polyline ( array $coordinate_array ) : GmagickDraw public rectangle ( float $x1 , float $y1 , float $x2 , float $y2 ) : GmagickDraw public rotate ( float $degrees ) : GmagickDraw public roundrectangle ( float $x1 , float $y1 , float $x2 , float $y2 , float $rx , float $ry ) : GmagickDraw public scale ( float $x , float $y ) : GmagickDraw public setfillcolor ( mixed $color ) : GmagickDraw public setfillopacity ( float $fill_opacity ) : GmagickDraw public setfont ( string $font ) : GmagickDraw public setfontsize ( float $pointsize ) : GmagickDraw public setfontstyle ( int $style ) : GmagickDraw public setfontweight ( int $weight ) : GmagickDraw public setstrokecolor ( mixed $color ) : GmagickDraw public setstrokeopacity ( float $stroke_opacity ) : GmagickDraw public setstrokewidth ( float $width ) : GmagickDraw public settextdecoration ( int $decoration ) : GmagickDraw public settextencoding ( string $encoding ) : GmagickDraw }
GmagickPixel类
GmagickPixel { /* 方法 */ public __construct ([ string $color ] ) public getcolor ([ bool $as_array = FALSE [, bool $normalize_array = FALSE ]] ) : mixed public getcolorcount ( void ) : int public getcolorvalue ( int $color ) : float public setcolor ( string $color ) : GmagickPixel public setcolorvalue ( int $color , float $value ) : GmagickPixel }