语法

bool imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )

参数

dst_image 目标图象连接资源。
src_image 源图象连接资源。
dst_x 目标 X 坐标点。
dst_y 目标 Y 坐标点。
src_x 源的 X 坐标点。
src_y 源的 Y 坐标点。
dst_w 目标宽度。
dst_h 目标高度。
src_w 源图象的宽度。
src_h 源图象的高度。

 成功时返回 TRUE, 或者在失败时返回 FALSE

案例

案例(图像裁减):

<?php
$targ_w = $targ_h = 150; // 设置目标宽度与高度
$jpeg_quality = 90; // 图片质量90,满分为100 $src = 'demo_files/pool.jpg'; // 被处理的图片
$img_r = imagecreatefromjpeg($src); // 获取原图
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h ); // 获取新图 imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']); // 目标图 源图 目标X坐标点 目标Y坐标点 源的X坐标点 源的Y坐标点 目标宽度 目标高度 源图宽度 源图高度
header('Content-type: image/jpeg');
imagejpeg($dst_r,null,$jpeg_quality); // 输出图象到浏览器或文件
?>

案例二(重新取样):

<?php
// 源文件
$filename = '1.jpg'; // 设置最大宽高
$width = 400;
$height = 400; // Content type
header('Content-Type: image/jpeg'); // 获取新尺寸
list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
} // 重新取样
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // 输出
imagejpeg($image_p, null, 100);
?>

附上上传图片的三种思路

1.选择图片,提交表单,服务器统一处理上传,保存路径

2.选择图片,上传,获取路径,提交表单,保存路径

3.选择图片,上传到服务器,通过某种途径获取到服务器的图片,保存到本地

  

php图像处理函数imagecopyresampled的更多相关文章

  1. Matlab图像处理函数:regionprops

    本篇文章为转载,仅为方便学术讨论所用,不用于商业用途.由于时间较久,原作者以及原始链接暂时无法找到,如有侵权以及其他任何事宜欢迎跟我联系,如有侵扰,在此提前表示歉意.----------------- ...

  2. php GD 和图像处理函数, 用 STHUPO.TTF 字体向图像写入文本

    php GD 和图像处理函数,   用  STHUPO.TTF 字体向图像写入文本 注意: 01)   imagettftext() 这个函数不能使用相对路径, 要想使用相对路径要先使用  puten ...

  3. php GD 和图像处理函数, 制作一张图片

    php GD 和图像处理函数, 制作一张图片 // GD 和图像处理函数 // https://www.php.net/manual/zh/ref.image.php // https://www.p ...

  4. MATLAB图像处理函数汇总(二)

    60.imnoise 功能:增加图像的渲染效果. 语法: J = imnoise(I,type) J = imnoise(I,type,parameters) 举例 I = imread('eight ...

  5. opencv 简单、常用的图像处理函数(2)

    opencv的项目以来配置和环境变量的配置都很简单,对于我这个没有c++基础的来说,复杂的是opencv的api和一些大部分来自国外没有翻译的资料,以及一些常见的编码问题. 资料 opencv 中文a ...

  6. php 图像处理函数

    gd_info       函数:获取当前安装的GD库的信息 getimagesize  函数:获取图像的大小 image_type_to_extension   函数:获取图像类型的文件后缀 ima ...

  7. php图像处理函数image_type_to_extension、image_type_to_mime_type 的区别

    php中获得图像类型的两个函数image_type_to_extension.image_type_to_mime_type,做图像处理的时候一直不清楚这俩个函数有什么区别,今天特意查了一下,有了一些 ...

  8. MATLAB图像处理函数汇总(一)

    1.applylut功能: 在二进制图像中利用lookup表进行边沿操作.语法:A = applylut(BW,lut)举例lut = makelut('sum(x(:)) == 4',2);BW1 ...

  9. 图像处理函数详解——im2bw

    im2bw是基于转换为二值图像的算法,用的是otsu's method. matlab中DIP工具箱函数im2bw使用阈值(threshold)变换法把灰度图像(grayscale image)转换成 ...

随机推荐

  1. 本地测试ajax遇到的跨域问题

    浏览器console问题描述:Cross origin requests are only supported for protocol schemes: http, data, chrome, ch ...

  2. 源码安装LNMP与搭建Zabbix

    系统环境:CentOS release 6.5 (Final) 搭建Zabbix 3.0对PHP环境要求>= 5.4 一.下载NMP的软件包: N:wget http://nginx.org/d ...

  3. 报错HTTP Status 500 - HHH000142: Javassist Enhancement failed: cn.itcast.entity.Customer; nested exception is org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: cn.itcast.entity.

    报错 type Exception report message HHH000142: Javassist Enhancement failed: cn.itcast.entity.Customer; ...

  4. python之linecache使用

    Python linecache模块缓存读取大文件指定行 linecache模块的作用是将文件内容读取到内存中,进行缓存,而不是每次都要从硬盘中读取,这样效率提高很多,又省去了对硬盘IO控制器的频繁操 ...

  5. C# 语言版本

    (摘自:维基百科)https://en.wikipedia.org/wiki/C_Sharp_(programming_language) Versions Version Language spec ...

  6. ultraedit使用记录

    ultraedit使用记录 10:57:33 在日常的工作中,我经常用keil进行程序的编写等工作,不过在编写过程中Keil对中文的支持不是很好,容易发生问题:同事推荐我用ultraedit进行程序的 ...

  7. LeetCode OJ:Search Insert Position(查找插入位置)

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  8. Week03-Java学习笔记第三次作业

    Week03-面向对象入门 1.本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识点组织起来.请使用工具画出本周学习到的知识点及知识点之间的联系. ...

  9. 转一篇pgpool配置

    转一篇pgpool配置 http://dz.sdut.edu.cn/blog/subaochen/2013/08/postgresql-9-1的failover配置及其管理/ 环境介绍 在两台虚拟机上 ...

  10. int 21h 汇编

    INT 21H 指令说明及使用方法 转自http://www.cnblogs.com/ynwlgh/archive/2011/12/12/2285017.html 很多初学汇编语言的同学可能会对INT ...