php分割图片全是黑色,图片全是黑的

namespace Org\Util;

class ThumbImage{

/**

* 图片信息

*/

private $info;

/**

* 内存中的图片

*/

private $image;

public function __construct($url){

$info = getimagesize($url);

$this->info = array(

'width' => $info['0'],

'height'=> $info['1'],

'type'  => image_type_to_extension($info['2'],false),

'mime'  => $info['mime'],

);

$fun = "imagecreatefrom{$this->info['type']}";

$this ->image = $fun($url);

}

public function ThumbImage($width,$height){

//创建缩略图

$thumbImage = imagecreatetruecolor($width, $height);

//把原图复制到缩略图上面

imagecopyresampled($thumbImage, $this->image, 0, 0, 0, 0, $width, $height, $this->info['width'], $this->info['height']);

//销毁内存中的原图

imagedestroy($this->image);

$this->image = $thumbImage;

}

//在浏览器中显示图片

public function showImage(){

header("content-type:".$this->info['mime']);

$fun = "image{$this->info['type']}";

$fun($this->image);

}

//保存图片到硬盘里

public function saveImage($newName){

$fun = "image{$this->info['type']}";

$fun($this->image,$newName.'.'.$this->info['type']);

}

//销毁图片

public function __destruct(){

imagedestroy($this->image);

}

}

c8d9615e201b9bb06d78b320ac3e8590.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值