The Imagick part of the image library developed for the bone system, which supports GIF, perfectly supports trimming, generating thumbnails, and adding watermarks.
Supports generating thumbnail images by orientation, such as:
The upper left corner of the priority $image->resize_to (the "north_west");//Right Priority $image->resize_to (+, +, ' East ');
More parameters See source code
Original
:
Call Mode:
imagick.class.php
<?php/* @ Version Date: Version Date: January 18, 2012 @ Copyright: Intelligence (http://www.1024i.com) obtaining permission to use this class library, you must retain the copyright notice information. To report a bug, comment or suggestion, please contact Lou Barnes (iua1024@gmail.com) */class Lib_image_imagick {private $image = null; private $type = null;// Constructor public Function __construct () {}//destructor public Function __destruct () {if ($this->image!==null) $this->IMAGE-&G T;destroy (); }//Load image Public Function open ($path) {$this->image = new Imagick ($path); if ($this->image) {$this->type = str ToLower ($this->image->getimageformat ()); } return $this->image; Public function crop ($x =0, $y =0, $width =null, $height =null) {if ($width ==null) $width = $this->image->getimagewid Th ()-$x; if ($height ==null) $height = $this->image->getimageheight ()-$y; if ($width <=0 | | $height <=0) return; if ($this->type== ' gif ') {$image = $this->image; $canvas = new Imagick (); $images = $image->coalesceimages (); fore Ach ($images as $frame) {$img = new Imagick (); $img->readimageblob ($FRAME); $img->cropimage ($width, $height, $x, $y); $canvas->addimage ($IMG); $canvas->setimagedelay ($img->getimagedelay ()); $canvas->setimagepage ($width, $height, 0, 0); } $image->destroy (); $this->image = $canvas; } else {$this->image->cropimage ($width, $height, $x, $y);}} /* Change image size $fit: Fit size ' Force ': Forces the picture to form $width X $height size ' scale ': scales the picture proportionally in the safe box $width X $height, and the image size is not exactly equal to the output after scaling $w Idth X $height ' Scale_fill ': Scale the picture proportionally in the safe box $width X $height, where there is no pixels inside the security box fill color, you can set the background fill color when using this parameter $BG _color = Array (255,255,255) ( Red, green, blue, transparency) transparency (0 opaque-127 fully transparent)) Other: Smart mode can scale the image and load the middle part of the image $width X $height pixel size $fit = ' force ', ' scale ', ' Scale_fill ' When: Output full image $fit = Image Azimuth value, output the corresponding relationship between the image letter and the image in the specified position: north_west North north_east West Center East south_west South South_east */Publ IC function resize_to ($width = $height, $fit = ' center ', $fill _color = Array (255,255,255,0)) {switch ($fit) { Case ' Force ': if ($this->type== ' gif ') {$image = $this->image; $canvas = new ImaGick (); $images = $image->coalesceimages (); foreach ($images as $frame) {$img = new Imagick (); $img->readimageblob ($frame); $img->thumbnailimage ($width, $ Height, false); $canvas->addimage ($IMG); $canvas->setimagedelay ($img->getimagedelay ()); } $image->destroy (); $this->image = $canvas; } else {$this->image->thumbnailimage ($width, $height, false);} break; Case ' scale ': if ($this->type== ' gif ') {$image = $this->image; $images = $image->coalesceimages (); $canvas = new I Magick (); foreach ($images as $frame) {$img = new Imagick (); $img->readimageblob ($frame); $img->thumbnailimage ($width, $ Height, true); $canvas->addimage ($IMG); $canvas->setimagedelay ($img->getimagedelay ()); } $image->destroy (); $this->image = $canvas; } else {$this->image->thumbnailimage ($width, $height, True);} break; Case ' Scale_fill ': $size = $this->image->getimagepage (); $SRC _width = $size [' width ']; $SRC _height = $size [' height ']; $x = 0; $y = 0; $DST _width = $width; $DST _height = $height; if ($src _width* $height > $src _height* $width) {$dst _height = intval ($width * $src _height/$src _width); $y = Intval (($ height-$dst _height)/2); } else {$dst _width = intval ($height * $src _width/$src _height), $x = Intval (($width-$DST _width)/2);} $image = $this->i Mage $canvas = new Imagick (); $color = ' Rgba ('. $fill _color[0]. ', '. $fill _color[1]. ', '. $fill _color[2]. ', '. $fill _color[3]. '; if ($this->type== ' gif ') {$images = $image->coalesceimages (); foreach ($images as $frame) {$frame Thumbnailimage ($width, $height, true); $draw = new Imagickdraw (); $draw->composite ($frame->getimagecompose (), $x, $y, $dst _width, $dst _height, $frame); $img = new Imagick (); $img->newimage ($width, $height, $color, ' gif '); $img->drawimage ($draw); $canvas->addimage ($IMG); $canvas->setimagedelay ($img->getimagedelay ()); $canvas->setimagepage ($width, $height, 0, 0); }} else {$image->thumbnailimage ($width, $heighT, true); $draw = new Imagickdraw (); $draw->composite ($image->getimagecompose (), $x, $y, $dst _width, $dst _height, $image); $canvas->newimage ($width, $height, $color, $this->get_type ()); $canvas->drawimage ($draw); $canvas->setimagepage ($width, $height, 0, 0); } $image->destroy (); $this->image = $canvas; Break Default: $size = $this->image->getimagepage (); $SRC _width = $size [' width ']; $SRC _height = $size [' height ']; $crop _x = 0; $crop _y = 0; $crop _w = $src _width; $crop _h = $src _height; if ($src _width* $height > $src _height* $width) {$crop _w = intval ($src _height* $width/$height);} else {$crop _h = intval ($ src_width* $height/$width); } switch ($fit) {case ' north_west ': $crop _x = 0, $crop _y = 0; break, case ' North ': $crop _x = Intval (($src _width-$crop _w)/ 2); $crop _y = 0; Break Case ' north_east ': $crop _x = $src _width-$crop _w; $crop _y = 0; Break Case ' West ': $crop _x = 0; $crop _y = Intval (($src _height-$crop _h)/2); Break Case ' center ': $crop _x = intval ($src_width-$crop _w)/2); $crop _y = Intval (($src _height-$crop _h)/2); Break Case ' East ': $crop _x = $src _width-$crop _w; $crop _y = Intval (($src _height-$crop _h)/2); Break Case ' south_west ': $crop _x = 0; $crop _y = $src _height-$crop _h; Break Case ' South ': $crop _x = Intval (($src _width-$crop _w)/2); $crop _y = $src _height-$crop _h; Break Case ' south_east ': $crop _x = $src _width-$crop _w; $crop _y = $src _height-$crop _h; Break Default: $crop _x = Intval (($src _width-$crop _w)/2); $crop _y = Intval (($src _height-$crop _h)/2); } $image = $this->image; $canvas = new Imagick (); if ($this->type== ' gif ') {$images = $image->coalesceimages (); foreach ($images as $frame) {$img = new Imagick (); $img- >readimageblob ($frame); $img->cropimage ($crop _w, $crop _h, $crop _x, $crop _y); $img->thumbnailimage ($width, $height, true); $canvas->addimage ($IMG); $canvas->setimagedelay ($img->getimagedelay ()); $canvas->setimagepage ($width, $height, 0, 0); }} else {$image->cropimage ($crop_w, $crop _h, $crop _x, $crop _y); $image->thumbnailimage ($width, $height, true); $canvas->addimage ($image); $canvas->setimagepage ($width, $height, 0, 0); } $image->destroy (); $this->image = $canvas; }}//Add Watermark Picture Public Function Add_watermark ($path, $x = 0, $y = 0) {$watermark = new Imagick ($path); $draw = new IMAGICKD Raw (); $draw->composite ($watermark->getimagecompose (), $x, $y, $watermark->getimagewidth (), $watermark Getimageheight (), $watermark); if ($this->type== ' gif ') {$image = $this->image; $canvas = new Imagick (); $images = $image->coalesceimages (); fore Ach ($image as $frame) {$img = new Imagick (); $img->readimageblob ($frame); $img->drawimage ($draw); $canvas AddImage ($IMG); $canvas->setimagedelay ($img->getimagedelay ()); } $image->destroy (); $this->image = $canvas; } else {$this->image->drawimage ($draw);}} Add watermark Text Public function Add_text ($text, $x = 0, $y = 0, $angle =0, $style =array ()) {$draw = new ImAgickdraw (); if (Isset ($style [' font ')]) $draw->setfont ($style [' font ']); if (Isset ($style [' font_size '])) $draw->setfontsize ($style [' font_size ']); if (Isset ($style [' Fill_color '])) $draw->setfillcolor ($style [' Fill_color ']); if (Isset ($style [' Under_color '])) $draw->settextundercolor ($style [' Under_color ']); if ($this->type== ' gif ') {foreach ($this->image as $frame) {$frame->annotateimage ($draw, $x, $y, $angle, $text); }} else {$this->image->annotateimage ($draw, $x, $y, $angle, $text);}} Save to the specified path public function save_to ($path) {if ($this->type== ' gif ') {$this->image->writeimages ($path, True);} else {$this->image->writeimage ($path);}} Output image Public Function output ($header = True) {if ($header) header (' Content-type: '. $this->type); Echo $this->image ->getimagesblob (); The Public Function get_width () {$size = $this->image->getimagepage (), Return $size [' width '];} public Function Get_h Eight () {$size = $this->image->getimagepagE (); return $size [' height ']; }//Set the image type, the default is the same as the source type public Function set_type ($type = ' png ') {$this->type = $type; $this->image->setimageformat ($type); }//Gets the source image type Public Function Get_type () {return $this->type;}//Whether the current object is a picture public function is_image () {if ($this-> ; image) return true; else return false; The public function thumbnail ($width = $height, $fit = True) {$this->image->thumbnailimage ($width, $height , $fit);} Create thumbnails $fit true to maintain proportions and generate thumbnails in the safe box $width X $height/* Add a border $width: Left and Right border width $height: top and Bottom Border width $color: color: RGB color ' rgb (255,0 , 0) ' or 16 binary color ' #FF0000 ' or color word ' white '/' red ' ... * * Public function border ($width, $height, $color = ' rgb (220, 220, 220) ') {$ Color=new Imagickpixel (); $color->setcolor ($color); $this->image->borderimage ($color, $width, $height); The Public function blur ($radius, $sigma) {$this->image->blurimage ($radius, $sigma);}//Blur public function Gaussian_ Blur ($radius, $sigma) {$this->image->gaussianblurimage ($radius, $sigma);} Gaussian Blur public Function Motion_blur ($radius, $sigma, $angle) {$this->image->motionblurimage ($radius, $sigma, $ angle);} Motion blur Public Function Radial_blur ($radius) {$this->image->radialblurimage ($radius);}//radial blur public function add _noise ($type =null) {$this->image->addnoiseimage ($type ==null?imagick::noise_impulse: $type);}//Add noise public function level ($black _point, $gamma, $white _point) {$this->image->levelimage ($black _point, $gamma, $white _ point);} Adjust levels Public Function modulate ($brightness, $saturation, $hue) {$this->image->modulateimage ($brightness, $ saturation, $hue);} Adjust brightness, saturation, hue public function charcoal ($radius, $sigma) {$this->image->charcoalimage ($radius, $sigma);}//Sketch Public Function Oil_paint ($radius) {$this->image->oilpaintimage ($radius);}//Oil painting effect public function flop () {$this- >image->flopimage ();} Flip Public Function Flip () {$this->image->flipimage ();}//Flip vertically}