php图像处理函数imagecopyresampled
语法
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的更多相关文章
- Matlab图像处理函数:regionprops
本篇文章为转载,仅为方便学术讨论所用,不用于商业用途.由于时间较久,原作者以及原始链接暂时无法找到,如有侵权以及其他任何事宜欢迎跟我联系,如有侵扰,在此提前表示歉意.----------------- ...
- php GD 和图像处理函数, 用 STHUPO.TTF 字体向图像写入文本
php GD 和图像处理函数, 用 STHUPO.TTF 字体向图像写入文本 注意: 01) imagettftext() 这个函数不能使用相对路径, 要想使用相对路径要先使用 puten ...
- php GD 和图像处理函数, 制作一张图片
php GD 和图像处理函数, 制作一张图片 // GD 和图像处理函数 // https://www.php.net/manual/zh/ref.image.php // https://www.p ...
- MATLAB图像处理函数汇总(二)
60.imnoise 功能:增加图像的渲染效果. 语法: J = imnoise(I,type) J = imnoise(I,type,parameters) 举例 I = imread('eight ...
- opencv 简单、常用的图像处理函数(2)
opencv的项目以来配置和环境变量的配置都很简单,对于我这个没有c++基础的来说,复杂的是opencv的api和一些大部分来自国外没有翻译的资料,以及一些常见的编码问题. 资料 opencv 中文a ...
- php 图像处理函数
gd_info 函数:获取当前安装的GD库的信息 getimagesize 函数:获取图像的大小 image_type_to_extension 函数:获取图像类型的文件后缀 ima ...
- php图像处理函数image_type_to_extension、image_type_to_mime_type 的区别
php中获得图像类型的两个函数image_type_to_extension.image_type_to_mime_type,做图像处理的时候一直不清楚这俩个函数有什么区别,今天特意查了一下,有了一些 ...
- MATLAB图像处理函数汇总(一)
1.applylut功能: 在二进制图像中利用lookup表进行边沿操作.语法:A = applylut(BW,lut)举例lut = makelut('sum(x(:)) == 4',2);BW1 ...
- 图像处理函数详解——im2bw
im2bw是基于转换为二值图像的算法,用的是otsu's method. matlab中DIP工具箱函数im2bw使用阈值(threshold)变换法把灰度图像(grayscale image)转换成 ...
随机推荐
- 爬虫第六篇:scrapy框架爬取某书网整站爬虫爬取
新建项目 # 新建项目$ scrapy startproject jianshu# 进入到文件夹 $ cd jainshu# 新建spider文件 $ scrapy genspider -t craw ...
- 记升级mysql后的一次故障
一.问题背景 接上级要求,某生产数据库需要实施备份:刚好漏洞扫描报告出来,mysql 版本需要升级到5.7.20,于是就未雨绸缪,先写脚本.脚本在mysql旧版本下完全可用(未升级前,mysql 为5 ...
- python线程、进程和协程
链接:http://www.jb51.net/article/88825.htm 引言 解释器环境:python3.5.1 我们都知道python网络编程的两大必学模块socket和socketser ...
- jfinal微信支付
private static final String appid = PropKit.get("appid"); //应用ID private static final Stri ...
- 22-THREE.JS 面材质
<!DOCTYPE html> <html> <head> <title>Example 04.05 - Mesh face material</ ...
- 记录下MD5加密遇到的坑
错误的写法: public static String md5(String plainText) { byte[] secretBytes = null; try { secretBytes = M ...
- Python基础学习(第3天)
第6课 循环 1.for 元素 in 序列: statement Python的新函数range():新建一个数列,都是整数,从0开始,下一个元素比上一个元素大1,一直到数列的上限(不包括上限).PS ...
- The Saltwater Room
I opened my eyes last night and saw you in the low light 昨夜我睁开眼,看见你在昏暗的灯光下 Walking down by the bay, ...
- New Concept English three (35)
27 55 The word justice is usually associated with courts of law. We might say that justice has been ...
- git配置ssh key并从github.com拉取repos
一.配置ssh key 1. 进入当前用户目录cd ~2. 生成ssh keyssh-keygen -t rsa -C "ABC@qq.com"ABC@qq.com账号必须是你登录 ...