|
@@ -399,7 +399,7 @@ class Img
|
|
|
if ($key == false) {
|
|
|
return $this->$name;
|
|
|
} else {
|
|
|
- return $this->$name[$key];
|
|
|
+ return $this->{$name}[$key];
|
|
|
}
|
|
|
} else {
|
|
|
$this->_error($name . ' error');
|
|
@@ -431,7 +431,7 @@ class Img
|
|
|
$this->_image = $this->_gd_get($this->_source);
|
|
|
break;
|
|
|
case 'im' :
|
|
|
- $this->_image = new \Imagick($this->_source);
|
|
|
+ $this->_image = $this->_im_get($this->_source);
|
|
|
$this->_imageType = strtolower($this->_image->getImageFormat());
|
|
|
break;
|
|
|
}
|
|
@@ -883,12 +883,12 @@ class Img
|
|
|
$dest_y = $offset[1];
|
|
|
}
|
|
|
//echo $dest_y;die;
|
|
|
- $this->_image = new \Imagick($this->_source);
|
|
|
+ $this->_image = $this->_im_get($this->_source);
|
|
|
$this->_image->thumbnailImage($dest_x, $dest_y);
|
|
|
|
|
|
if (isset($offset[2]) && $offset[2] == 3) {
|
|
|
/* 按照缩略图大小创建一个有颜色的图片 */
|
|
|
- $canvas = new \Imagick();
|
|
|
+ $canvas = $this->_im_get();
|
|
|
$color = new \ImagickPixel("white");
|
|
|
$canvas->newImage($offset[0], $offset[1], $color, 'png');
|
|
|
//$canvas->paintfloodfillimage('transparent',2000,NULL,0,0);
|
|
@@ -996,7 +996,7 @@ class Img
|
|
|
}
|
|
|
|
|
|
if ($this->_dropSize) {
|
|
|
- $this->_image = new \Imagick($this->_dest['crop'][$k]);
|
|
|
+ $this->_image = $this->_im_get($this->_dest['crop'][$k]);
|
|
|
$source_x = $this->_image->getImageWidth();
|
|
|
$source_y = $this->_image->getImageHeight();
|
|
|
} else {
|
|
@@ -1065,7 +1065,7 @@ class Img
|
|
|
|
|
|
private function _im_gif($w, $h, $x, $y, $d = false, $num = false)
|
|
|
{
|
|
|
- $canvas = new \Imagick();
|
|
|
+ $canvas = $this->_im_get();
|
|
|
|
|
|
$canvas->setFormat("gif");
|
|
|
|
|
@@ -1076,7 +1076,7 @@ class Img
|
|
|
for ($i = 0; $i < $num; $i++) {
|
|
|
$this->_image->setImageIndex($i);
|
|
|
|
|
|
- $img = new \Imagick();
|
|
|
+ $img = $this->_im_get();
|
|
|
$img->readImageBlob($this->_image);
|
|
|
|
|
|
if ($d != false) {
|
|
@@ -1115,7 +1115,7 @@ class Img
|
|
|
if (isset($this->_mark['radius'])) {
|
|
|
$water = $this->_im_radius($this->_mark['water'], $this->_mark['radius']);
|
|
|
} else {
|
|
|
- $water = new \Imagick($this->_mark['water']);
|
|
|
+ $water = $this->_im_get($this->_mark['water']);
|
|
|
}
|
|
|
$draw = new \ImagickDraw();
|
|
|
|
|
@@ -1161,30 +1161,61 @@ class Img
|
|
|
if ($this->_setup == true || !file_exists($this->_dest['txt'])) {
|
|
|
|
|
|
$draw = new \ImagickDraw();
|
|
|
- if(isset($this->_txt['font'])) $draw->setFont($this->_txt['font']);
|
|
|
- if(isset($this->_txt['size'])) $draw->setFontSize($this->_txt['size']);
|
|
|
- if(isset($this->_txt['color'])) $draw->setFillColor($this->_txt['color']);
|
|
|
- if(isset($this->_txt['bgcolor'])) $draw->setTextUnderColor($this->_txt['bgcolor']);
|
|
|
+ if (isset($this->_txt['font'])) {
|
|
|
+ $draw->setFont($this->_txt['font']);
|
|
|
+ }
|
|
|
+ if (isset($this->_txt['size'])) {
|
|
|
+ $draw->setFontSize($this->_txt['size']);
|
|
|
+ }
|
|
|
+ if (isset($this->_txt['color'])) {
|
|
|
+ $draw->setFillColor($this->_txt['color']);
|
|
|
+ }
|
|
|
+ if (isset($this->_txt['bgcolor'])) {
|
|
|
+ $draw->setTextUnderColor($this->_txt['bgcolor']);
|
|
|
+ }
|
|
|
+ if (!isset($this->_txt['top'])) {
|
|
|
+ $this->_txt['top'] = 0;
|
|
|
+ }
|
|
|
+ if (!isset($this->_txt['left'])) {
|
|
|
+ $this->_txt['left'] = 0;
|
|
|
+ }
|
|
|
|
|
|
if ($this->_imageType == 'gif') {
|
|
|
foreach ($this->_image as $frame) {
|
|
|
- $frame->annotateImage($draw, 0, 0, $this->_txt['angle'], $this->_txt['name']);
|
|
|
+ $frame->annotateImage($draw, $this->_txt['left'], $this->_txt['top'], $this->_txt['angle'], $this->_txt['name']);
|
|
|
}
|
|
|
} else {
|
|
|
- $this->_image->annotateImage($draw, 0, 0, $this->_txt['angle'], $this->_txt['name']);
|
|
|
+ $this->_image->annotateImage($draw, $this->_txt['left'], $this->_txt['top'], $this->_txt['angle'], $this->_txt['name']);
|
|
|
}
|
|
|
|
|
|
$this->_image->writeImage($this->_dest['txt']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @desc 获取数据源
|
|
|
+ * @param *
|
|
|
+ */
|
|
|
+ private function _im_get($image = false)
|
|
|
+ {
|
|
|
+ if ($image && strstr($image, 'http')) {
|
|
|
+ $content = file_get_contents($image);
|
|
|
+ $im = new \Imagick();
|
|
|
+ $im->readImageBlob($content);
|
|
|
+ } else {
|
|
|
+ $im = new \Imagick($image);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $im;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @desc 圆角图片
|
|
|
* @param *
|
|
|
*/
|
|
|
private function _im_radius($img = '', $radius = -1)
|
|
|
{
|
|
|
- $image = new \Imagick($img);
|
|
|
+ $image = $this->_im_get($img);
|
|
|
$image->setImageFormat('png');
|
|
|
if ($radius == -1) {
|
|
|
$x = $image->getImageWidth() / 2;
|