PHP添加PNG图片背景透明水印

图片相关操作类

class ImageTool
{
   
    private $imagePath;//图片路径
    private $outputDir;//输出文件夹
    public $memoryImg;//内存图像
    public $path;
    public function __construct($imagePath, $outputDir = null)
    {
   
        $this->imagePath = $imagePath;
        $this->outputDir = $outputDir;
        $this->memoryImg = null;
        $this->path = null;

    }

    /**
     * 显示内存中的图片
     * @param $image
     */
    public function showImage()
    {
   
        if ($this->memoryImg != null) {
            $info = getimagesize($this->imagePath);
            $type = image_type_to_extension($info[2], false);
            header('Content-type:' . $info['mime']);
            $funs = "image{$type}";
            $funs($this->memoryImg);
            imagedestroy($this->memoryImg);
            $this->memoryImg = null;
        }
    }

    /**
     * 保存图片
     * @param $image    图片路径
     * @return string
     */
    private function saveImage($image)
    {
   
        $info = getimagesize($this->imagePath);
        $type = image_type_to_extension($info[2], false);
        $funs = "image{$type}";
        if (empty($this->outputDir)) {
            $funs($image, md5($this->imagePath) . '.' . $type);
            return md5($this->imagePath) . '.' . $type;
        } else {
            $funs($image, $this->outputDir . md5($this
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值