|
@@ -245,6 +245,9 @@ class Img
|
|
|
$this->setSetup($setup);
|
|
|
}
|
|
|
$this->setSource($source);
|
|
|
+ if (!$this->_image) {
|
|
|
+ return $source;
|
|
|
+ }
|
|
|
if ($name) $this->setName($name);
|
|
|
$this->setMark($water);
|
|
|
//if($position) $this->setPosition($position);
|
|
@@ -259,12 +262,30 @@ class Img
|
|
|
public function compress($source, $quality = 20, $name = false)
|
|
|
{
|
|
|
$this->setSource($source);
|
|
|
+ if (!$this->_image) {
|
|
|
+ return $source;
|
|
|
+ }
|
|
|
if ($name) $this->setName($name);
|
|
|
$this->setQuality($quality);
|
|
|
$this->loadMethod('compress');
|
|
|
return $this->getDest('compress');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @desc 对图片进行webp转换
|
|
|
+ * @param *
|
|
|
+ */
|
|
|
+ public function webp($source, $name = false)
|
|
|
+ {
|
|
|
+ $this->setSource($source);
|
|
|
+ if (!$this->_image) {
|
|
|
+ return $source;
|
|
|
+ }
|
|
|
+ if ($name) $this->setName($name);
|
|
|
+ $this->loadMethod('webp');
|
|
|
+ return $this->getDest('webp');
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @desc 构造函数 可批量建立
|
|
|
* @param *
|
|
@@ -286,6 +307,9 @@ class Img
|
|
|
$this->setSetup($setup);
|
|
|
}
|
|
|
$this->setSource($source);
|
|
|
+ if (!$this->_image) {
|
|
|
+ return $source;
|
|
|
+ }
|
|
|
if ($name) $this->setName($name);
|
|
|
foreach ($config as $k => $v) {
|
|
|
$k = $v['method'];
|
|
@@ -307,6 +331,9 @@ class Img
|
|
|
$this->setSetup($setup);
|
|
|
}
|
|
|
$this->setSource($source);
|
|
|
+ if (!$this->_image) {
|
|
|
+ return $source;
|
|
|
+ }
|
|
|
if ($name) $this->setName($name);
|
|
|
$this->setThumb($thumb);
|
|
|
$this->loadMethod('thumb');
|
|
@@ -324,6 +351,9 @@ class Img
|
|
|
$this->setSetup($setup);
|
|
|
}
|
|
|
$this->setSource($source);
|
|
|
+ if (!$this->_image) {
|
|
|
+ return $source;
|
|
|
+ }
|
|
|
if ($position) $this->setPosition($position);
|
|
|
if ($name) $this->setName($name);
|
|
|
$this->setCrop($crop);
|
|
@@ -343,6 +373,9 @@ class Img
|
|
|
}
|
|
|
|
|
|
$this->setSource($source);
|
|
|
+ if (!$this->_image) {
|
|
|
+ return $source;
|
|
|
+ }
|
|
|
if ($position) $this->setPosition($position);
|
|
|
if ($name) $this->setName($name);
|
|
|
$this->setCrop($size);
|
|
@@ -425,6 +458,9 @@ class Img
|
|
|
private function _image()
|
|
|
{
|
|
|
$this->_check('source');
|
|
|
+ if (!class_exists('\Imagick')) {
|
|
|
+ $this->_type = 'gd';
|
|
|
+ }
|
|
|
if (!$this->_image) {
|
|
|
switch ($this->_type) {
|
|
|
case 'gd' :
|
|
@@ -432,7 +468,10 @@ class Img
|
|
|
break;
|
|
|
case 'im' :
|
|
|
$this->_image = $this->_im_get($this->_source);
|
|
|
- $this->_imageType = strtolower($this->_image->getImageFormat());
|
|
|
+ if ($this->_image) {
|
|
|
+ $this->_imageType = strtolower($this->_image->getImageFormat());
|
|
|
+ }
|
|
|
+
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -622,6 +661,15 @@ class Img
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @desc 建立原图压缩图
|
|
|
+ * @param *
|
|
|
+ */
|
|
|
+ private function _gd_create_compress()
|
|
|
+ {
|
|
|
+ $this->_dest['compress'] = $this->_source;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @desc 建立剪切图
|
|
|
* @param *
|
|
@@ -995,6 +1043,19 @@ class Img
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @desc 设置webp格式
|
|
|
+ * @param *
|
|
|
+ */
|
|
|
+ private function _im_create_webp()
|
|
|
+ {
|
|
|
+ $this->_check('source');
|
|
|
+ $this->_dest['webp'] = $this->getName('.webp');
|
|
|
+
|
|
|
+ $this->_image->setFormat('webp');
|
|
|
+ $this->_image->writeImage($this->_dest['webp']);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @desc 建立裁切图
|
|
|
* @param *
|
|
@@ -1245,6 +1306,9 @@ class Img
|
|
|
*/
|
|
|
private function _im_get($image = false)
|
|
|
{
|
|
|
+ if (!is_file($image)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
if ($image && strstr($image, 'http')) {
|
|
|
$content = file_get_contents($image);
|
|
|
$im = new \Imagick();
|