本文整理汇总了PHP中resource::writeImage方法的典型用法代码示例。如果您正苦于以下问题:PHP resource::writeImage方法的具体用法?PHP resource::writeImage怎么用?PHP resource::writeImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource
的用法示例。
在下文中一共展示了resource::writeImage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* 保存图像
* @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);
}
}
示例2: save
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);
}
}
示例3: write
/**
* 将图片保存到指定位置
* @param string $image 图片输出路径
*/
public function write($image)
{
self::$resource->writeImage($image);
}
示例4: saveImageFile
/**
* 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;
}
}
}
示例5: imagickImage
/**
* 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;
}