목차
php gd等比例缩放压缩图片函数,
백엔드 개발 PHP 튜토리얼 php gd等比例缩放压缩图片函数,_PHP教程

php gd等比例缩放压缩图片函数,_PHP教程

Jul 12, 2016 am 08:49 AM
gd php 압축 그림

php gd等比例缩放压缩图片函数,

本文实例为大家分享了php gd等比例缩放压缩图片函数,供大家参考,具体内容如下

<&#63;php
  /**
   * desription 判断是否gif动画
   * @param sting $image_file图片路径
   * @return boolean t 是 f 否
   */
  function check_gifcartoon($image_file){
    $fp = fopen($image_file,'rb');
    $image_head = fread($fp,1024);
    fclose($fp);
    return preg_match("/".chr(0x21).chr(0xff).chr(0x0b).'NETSCAPE2.0'."/",$image_head)&#63;false:true;
  }

  /**
  * desription 压缩图片
  * @param sting $imgsrc 图片路径
  * @param string $imgdst 压缩后保存路径
  */
  function compressed_image($imgsrc,$imgdst){
    list($width,$height,$type)=getimagesize($imgsrc);
    $new_width = ($width>600&#63;600:$width)*0.9;
    $new_height =($height>600&#63;600:$height)*0.9;
    switch($type){
      case 1:
        $giftype=check_gifcartoon($imgsrc);
        if($giftype){
          header('Content-Type:image/gif');
          $image_wp=imagecreatetruecolor($new_width, $new_height);
          $image = imagecreatefromgif($imgsrc);
          imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
          //75代表的是质量、压缩图片容量大小
          imagejpeg($image_wp, $imgdst,75);
          imagedestroy($image_wp);
        }
        break;
      case 2:
        header('Content-Type:image/jpeg');
        $image_wp=imagecreatetruecolor($new_width, $new_height);
        $image = imagecreatefromjpeg($imgsrc);
        imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
        //75代表的是质量、压缩图片容量大小
        imagejpeg($image_wp, $imgdst,75);
        imagedestroy($image_wp);
        break;
      case 3:
        header('Content-Type:image/png');
        $image_wp=imagecreatetruecolor($new_width, $new_height);
        $image = imagecreatefrompng($imgsrc);
        imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
        //75代表的是质量、压缩图片容量大小
        imagejpeg($image_wp, $imgdst,75);
        imagedestroy($image_wp);
        break;
    }
  }

로그인 후 복사

php and gd 函数参考表
gd_info 取得当前安装的 GD 库的信息
getimagesize 取得图像大小
getimagesizefromstring Get the size of an image from a string
image_type_to_extension 取得图像类型的文件后缀
image_type_to_mime_type 取得 getimagesize,exif_read_data,exif_thumbnail,exif_imagetype 所返回的图像类型的 MIME 类型
image2wbmp 以 WBMP 格式将图像输出到浏览器或文件
imageaffine Return an image containing the affine tramsformed src image, using an optional clipping area
imageaffinematrixconcat Concat two matrices (as in doing many ops in one go)
imageaffinematrixget Return an image containing the affine tramsformed src image, using an optional clipping area
imagealphablending 设定图像的混色模式
imageantialias 是否使用抗锯齿(antialias)功能
imagearc 画椭圆弧
imagechar 水平地画一个字符
imagecharup 垂直地画一个字符
imagecolorallocate 为一幅图像分配颜色
imagecolorallocatealpha 为一幅图像分配颜色 + alpha
imagecolorat 取得某像素的颜色索引值
imagecolorclosest 取得与指定的颜色最接近的颜色的索引值
imagecolorclosestalpha 取得与指定的颜色加透明度最接近的颜色
imagecolorclosesthwb 取得与给定颜色最接近的色度的黑白色的索引
imagecolordeallocate 取消图像颜色的分配
imagecolorexact 取得指定颜色的索引值
imagecolorexactalpha 取得指定的颜色加透明度的索引值
imagecolormatch 使一个图像中调色板版本的颜色与真彩色版本更能匹配
imagecolorresolve 取得指定颜色的索引值或有可能得到的最接近的替代值
imagecolorresolvealpha 取得指定颜色 + alpha 的索引值或有可能得到的最接近的替代值
imagecolorset 给指定调色板索引设定颜色
imagecolorsforindex 取得某索引的颜色
imagecolorstotal 取得一幅图像的调色板中颜色的数目
imagecolortransparent 将某个颜色定义为透明色
imageconvolution 用系数 div 和 offset 申请一个 3x3 的卷积矩阵
imagecopy 拷贝图像的一部分
imagecopymerge 拷贝并合并图像的一部分
imagecopymergegray 用灰度拷贝并合并图像的一部分
imagecopyresampled 重采样拷贝部分图像并调整大小
imagecopyresized 拷贝部分图像并调整大小
imagecreate 新建一个基于调色板的图像
imagecreatefromgd2 从 GD2 文件或 URL 新建一图像
imagecreatefromgd2part 从给定的 GD2 文件或 URL 中的部分新建一图像
imagecreatefromgd 从 GD 文件或 URL 新建一图像
imagecreatefromgif 由文件或 URL 创建一个新图象。
imagecreatefromjpeg 由文件或 URL 创建一个新图象。
imagecreatefrompng 由文件或 URL 创建一个新图象。
imagecreatefromstring 从字符串中的图像流新建一图像
imagecreatefromwbmp 由文件或 URL 创建一个新图象。
imagecreatefromwebp 由文件或 URL 创建一个新图象。
imagecreatefromxbm 由文件或 URL 创建一个新图象。
imagecreatefromxpm 由文件或 URL 创建一个新图象。
imagecreatetruecolor 新建一个真彩色图像
imagecrop Crop an image using the given coordinates and size, x, y, width and height
imagecropauto Crop an image automatically using one of the available modes
imagedashedline 画一虚线
imagedestroy 销毁一图像
imageellipse 画一个椭圆
imagefill 区域填充
imagefilledarc 画一椭圆弧且填充
imagefilledellipse 画一椭圆并填充
imagefilledpolygon 画一多边形并填充
imagefilledrectangle 画一矩形并填充
imagefilltoborder 区域填充到指定颜色的边界为止
imagefilter 对图像使用过滤器
imageflip Flips an image using a given mode
imagefontheight 取得字体高度
imagefontwidth 取得字体宽度
imageftbbox 给出一个使用 FreeType 2 字体的文本框
imagefttext 使用 FreeType 2 字体将文本写入图像
imagegammacorrect 对 GD 图像应用 gamma 修正
imagegd2 将 GD2 图像输出到浏览器或文件
imagegd 将 GD 图像输出到浏览器或文件
imagegif 输出图象到浏览器或文件。
imagegrabscreen Captures the whole screen
imagegrabwindow Captures a window
imageinterlace 激活或禁止隔行扫描
imageistruecolor 检查图像是否为真彩色图像
imagejpeg 输出图象到浏览器或文件。
imagelayereffect 设定 alpha 混色标志以使用绑定的 libgd 分层效果
imageline 画一条线段
imageloadfont 载入一新字体
imagepalettecopy 将调色板从一幅图像拷贝到另一幅
imagepalettetotruecolor Converts a palette based image to true color
imagepng 以 PNG 格式将图像输出到浏览器或文件
imagepolygon 画一个多边形
imagepsbbox 给出一个使用 PostScript Type1 字体的文本方框
imagepsencodefont 改变字体中的字符编码矢量
imagepsextendfont 扩充或精简字体
imagepsfreefont 释放一个 PostScript Type 1 字体所占用的内存
imagepsloadfont 从文件中加载一个 PostScript Type 1 字体
imagepsslantfont 倾斜某字体
imagepstext 用 PostScript Type1 字体把文本字符串画在图像上
imagerectangle 画一个矩形
imagerotate 用给定角度旋转图像
imagesavealpha 设置标记以在保存 PNG 图像时保存完整的 alpha 通道信息(与单一透明色相反)
imagescale Scale an image using the given new width and height
imagesetbrush 设定画线用的画笔图像
imagesetinterpolation Set the interpolation method
imagesetpixel 画一个单一像素
imagesetstyle 设定画线的风格
imagesetthickness 设定画线的宽度
imagesettile 设定用于填充的贴图
imagestring 水平地画一行字符串
imagestringup 垂直地画一行字符串
imagesx 取得图像宽度
imagesy 取得图像高度
imagetruecolortopalette 将真彩色图像转换为调色板图像
imagettfbbox 取得使用 TrueType 字体的文本的范围
imagettftext 用 TrueType 字体向图像写入文本
imagetypes 返回当前 PHP 版本所支持的图像类型
imagewbmp 以 WBMP 格式将图像输出到浏览器或文件
imagewebp Output an WebP image to browser or file
imagexbm 将 XBM 图像输出到浏览器或文件
iptcembed 将二进制 IPTC 数据嵌入到一幅 JPEG 图像中
iptcparse 将二进制 IPTC 块解析为单个标记
jpeg2wbmp 将 JPEG 图像文件转换为 WBMP 图像文件
png2wbmp 将 PNG 图像文件转换为 WBMP 图像文件

以上就是本文的全部内容,希望对大家学习PHP程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1136663.htmlTechArticlephp gd等比例缩放压缩图片函数, 本文实例为大家分享了php gd等比例缩放压缩图片函数,供大家参考,具体内容如下 php /** * desription 判断是...
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

CakePHP 프로젝트 구성 CakePHP 프로젝트 구성 Sep 10, 2024 pm 05:25 PM

이번 장에서는 CakePHP의 환경 변수, 일반 구성, 데이터베이스 구성, 이메일 구성에 대해 알아봅니다.

Ubuntu 및 Debian용 PHP 8.4 설치 및 업그레이드 가이드 Ubuntu 및 Debian용 PHP 8.4 설치 및 업그레이드 가이드 Dec 24, 2024 pm 04:42 PM

PHP 8.4는 상당한 양의 기능 중단 및 제거를 통해 몇 가지 새로운 기능, 보안 개선 및 성능 개선을 제공합니다. 이 가이드에서는 Ubuntu, Debian 또는 해당 파생 제품에서 PHP 8.4를 설치하거나 PHP 8.4로 업그레이드하는 방법을 설명합니다.

CakePHP 날짜 및 시간 CakePHP 날짜 및 시간 Sep 10, 2024 pm 05:27 PM

cakephp4에서 날짜와 시간을 다루기 위해 사용 가능한 FrozenTime 클래스를 활용하겠습니다.

CakePHP 파일 업로드 CakePHP 파일 업로드 Sep 10, 2024 pm 05:27 PM

파일 업로드 작업을 위해 양식 도우미를 사용할 것입니다. 다음은 파일 업로드의 예입니다.

CakePHP 라우팅 CakePHP 라우팅 Sep 10, 2024 pm 05:25 PM

이번 장에서는 라우팅과 관련된 다음과 같은 주제를 학습하겠습니다.

CakePHP 토론 CakePHP 토론 Sep 10, 2024 pm 05:28 PM

CakePHP는 PHP용 오픈 소스 프레임워크입니다. 이는 애플리케이션을 훨씬 쉽게 개발, 배포 및 유지 관리할 수 있도록 하기 위한 것입니다. CakePHP는 강력하고 이해하기 쉬운 MVC와 유사한 아키텍처를 기반으로 합니다. 모델, 뷰 및 컨트롤러 gu

PHP 개발을 위해 Visual Studio Code(VS Code)를 설정하는 방법 PHP 개발을 위해 Visual Studio Code(VS Code)를 설정하는 방법 Dec 20, 2024 am 11:31 AM

VS Code라고도 알려진 Visual Studio Code는 모든 주요 운영 체제에서 사용할 수 있는 무료 소스 코드 편집기 또는 통합 개발 환경(IDE)입니다. 다양한 프로그래밍 언어에 대한 대규모 확장 모음을 통해 VS Code는

CakePHP 유효성 검사기 만들기 CakePHP 유효성 검사기 만들기 Sep 10, 2024 pm 05:26 PM

컨트롤러에 다음 두 줄을 추가하면 유효성 검사기를 만들 수 있습니다.

See all articles