/** * 保存图像 * @param string $imgname 图像保存名称 * @param string $type 图像类型 * @param boolean $interlace 是否对JPEG类型图像设置隔行扫描 */ public function save($imgname, $type = null, $interlace = true) { if (empty($this->img)) { throw new Exception('没有可以被保存的图像资源'); } //设置图片类型 if (is_null($type)) { $type = $this->info['type']; } else { $type = strtolower($type); $this->img->setImageFormat($type); } //JPEG图像设置隔行扫描 if ('jpeg' == $type || 'jpg' == $type) { $this->img->setImageInterlaceScheme(1); } //去除图像配置信息 $this->img->stripImage(); //保存图像 $imgname = realpath(dirname($imgname)) . '/' . basename($imgname); //强制绝对路径 if ('gif' == $type) { $this->img->writeImages($imgname, true); } else { $this->img->writeImage($imgname); } }
public function save($imgname, $type = NULL, $interlace = true) { if (empty($this->img)) { throw new Exception("没有可以被保存的图像资源"); } if (is_null($type)) { $type = $this->info["type"]; } else { $type = strtolower($type); $this->img->setImageFormat($type); } if ("jpeg" == $type || "jpg" == $type) { $this->img->setImageInterlaceScheme(1); } $this->img->stripImage(); $imgname = realpath(dirname($imgname)) . "/" . basename($imgname); if ("gif" == $type) { $this->img->writeImages($imgname, true); } else { $this->img->writeImage($imgname); } }
/** * 将图片保存到指定位置 * @param string $image 图片输出路径 */ public function write($image) { self::$resource->writeImage($image); }
/** * Save image from image resource * * @param resource $image * @param string $mime_type * @param string $filepath * @return boolean */ private function saveImageFile($image, $mime_type, $filepath) { if (osc_use_imagick()) { $image->setImageFileName($filepath); $image->writeImage(); } else { switch ($mime_type) { case 'image/jpeg': return imagejpeg($image, $filepath); case 'image/png': return imagepng($image, $filepath); case 'image/gif': return imagegif($image, $filepath); default: return false; } } }
/** * Output imagick image to file * * @param resource $img imagick image resource * @param string $filename The path to save the file to. * @param string $destformat The Image type to use for $filename * @param int $jpgQuality JEPG quality (1-100) * @return bool */ protected function imagickImage($img, $filename, $destformat, $jpgQuality = null) { if (!$jpgQuality) { $jpgQuality = $this->options['jpgQuality']; } try { if ($destformat) { if ($destformat === 'gif') { $img->setImageFormat('gif'); } else { if ($destformat === 'png') { $img->setImageFormat('png'); } else { if ($destformat === 'jpg') { $img->setImageFormat('jpeg'); } } } } if (strtoupper($img->getImageFormat()) === 'JPEG') { $img->setImageCompression(imagick::COMPRESSION_JPEG); $img->setImageCompressionQuality($jpgQuality); try { $orientation = $img->getImageOrientation(); } catch (ImagickException $e) { $orientation = 0; } $img->stripImage(); if ($orientation) { $img->setImageOrientation($orientation); } } $result = $img->writeImage($filename); } catch (Exception $e) { $result = false; } return $result; }