- 浏览: 214710 次
- 性别:
- 来自: 西安
文章分类
- 全部博客 (143)
- java (13)
- mongodb (15)
- linux (31)
- mysql (2)
- cache (1)
- Android (3)
- lucene (2)
- javascript (9)
- php (13)
- 人生 (2)
- solr (7)
- 跨域iframe (1)
- 统计学 (1)
- redis (0)
- amazon aws (2)
- 国内比较便宜的vps (1)
- nginx (5)
- sns api应用 (1)
- api (1)
- postfix (1)
- nodejs (1)
- gitlab (1)
- myeclipse (1)
- matlab (3)
- ubuntu (2)
- stardict (1)
- cdn (1)
- lajp (1)
- workerman (1)
- tensorflow (1)
- 协同推荐算法 (3)
- html5 (1)
- extensions (3)
- Rome (1)
- 正则 (1)
- EBS (1)
- python (5)
- https (1)
- iptables (1)
- facebook (0)
- ImageMagick (0)
- elasticsearch (1)
- Flask (1)
- wordpress (0)
- kubernetes (0)
最新评论
-
三尺寒冰:
怎么实现排序的?分析一下
php mongodb 实现group 并按照某字段排序
1.创建iamge处理类
<?php
include_once 'ImageResize.class.php';
date_default_timezone_set('PRC');
class Image {
protected $nameinfo;
protected $InputImageFileExtension;
public static function getInstance() {
static $instance;
if (!isset ($instance)) {
$class = __CLASS__;
$instance = new $class ();
}
return $instance;
}
function uploadresize($fileparam, $imageparam) {
$newW = $imageparam['imageW'];
$newH = $imageparam['imageH'];
$this->nameinfo = explode('.',$fileparam['name']);
//取得图片格式
$this->InputImageFileExtension = $this->nameinfo[1];
//判断是不是给了新的文件名
if(empty($imageparam['imagename'])){
$outputFileName = $this->nameinfo[0];
}else{
$outputFileName = $imageparam['imagename'];
}
//判断路径是否正确
if (!file_exists($imageparam['imagepath'])) {
if(!mkdir($imageparam['imagepath'])){
throw new Exception('image path is wrong');
exit;
}
}
$file_src = $imageparam['imagepath']."/". $outputFileName . "_." . $this->InputImageFileExtension;
// temporary safe image storage
if(file_exists($file_src)){
unlink($file_src);
}
move_uploaded_file($fileparam['tmp_name'], $file_src);
// set image size
$imageResize = new ImageResize();
$imageResize->my_image_resize($file_src,$file_src,$newW,$newH,$this->InputImageFileExtension);
}
}
?>
2.设置图片大小处理类:
<?php
class ImageResize {
/*
* 说明:函数功能是把一个图像裁剪为任意大小的图像,图像不变形
* 参数说明:输入 需要处理图片的 文件名,生成新图片的保存文件名,生成新图片的宽,生成新图片的高
* written by smallchicken
* time 2008-12-18
*/
// 获得任意大小图像,不足地方拉伸,不产生变形,不留下空白
function my_image_resize($src_file, $dst_file, $new_width, $new_height, $type) {
if ($new_width < 1 || $new_height < 1) {
echo "params width or height error !";
exit ();
}
if (! file_exists ( $src_file )) {
echo $src_file . " is not exists !";
exit ();
}
// 图像类型
$support_type = array ("jpg", "png", "gif" );
if (! in_array ( $type, $support_type, true )) {
echo "this type of image does not support! only support jpg , gif or png";
exit ();
}
//Load image
switch ($type) {
case "jpg" :
$src_img = imagecreatefromjpeg ( $src_file );
break;
case "png" :
$src_img = imagecreatefrompng ( $src_file );
break;
case "gif" :
$src_img = imagecreatefromgif ( $src_file );
break;
default :
echo "Load image error!";
exit ();
}
$w = imagesx ( $src_img );
$h = imagesy ( $src_img );
////
if($w < $new_width && $h < $new_height){
// 定义一个中间的临时图像,该图像的宽高比 正好满足目标要求
$inter_w = $w;
$inter_h = $h;
$inter_img = imagecreatetruecolor ( $inter_w, $inter_h );
imagecopy ( $inter_img, $src_img, 0, 0, 0, 0, $inter_w, $inter_h );
// 生成一个以最大边长度为大小的是目标图像$ratio比例的临时图像
// 定义一个新的图像
$new_img = imagecreatetruecolor ( $inter_w, $inter_h );
imagecopyresampled ( $new_img, $inter_img, 0, 0, 0, 0, $inter_w, $inter_w, $inter_h, $inter_h );
switch ($type) {
case "jpg" :
imagejpeg ( $new_img, $dst_file, 100 ); // 存储图像
break;
case "png" :
imagepng ( $new_img, $dst_file, 100 );
break;
case "gif" :
imagegif ( $new_img, $dst_file, 100 );
break;
default :
break;
}
die();
}
////
$ratio_w = 1.0 * $new_width / $w;
$ratio_h = 1.0 * $new_height / $h;
$ratio = 1.0;
// 生成的图像的高宽比原来的都小,或都大 ,原则是 取大比例放大,取大比例缩小(缩小的比例就比较小了)
if (($ratio_w < 1 && $ratio_h < 1) || ($ratio_w > 1 && $ratio_h > 1)) {
if ($ratio_w < $ratio_h) {
$ratio = $ratio_h; // 情况一,宽度的比例比高度方向的小,按照高度的比例标准来裁剪或放大
} else {
$ratio = $ratio_w;
}
// 定义一个中间的临时图像,该图像的宽高比 正好满足目标要求
$inter_w = ( int ) ($new_width / $ratio);
$inter_h = ( int ) ($new_height / $ratio);
$inter_img = imagecreatetruecolor ( $inter_w, $inter_h );
imagecopy ( $inter_img, $src_img, 0, 0, 0, 0, $inter_w, $inter_h );
// 生成一个以最大边长度为大小的是目标图像$ratio比例的临时图像
// 定义一个新的图像
$new_img = imagecreatetruecolor ( $new_width, $new_height );
imagecopyresampled ( $new_img, $inter_img, 0, 0, 0, 0, $new_width, $new_height, $inter_w, $inter_h );
switch ($type) {
case "jpg" :
imagejpeg ( $new_img, $dst_file, 100 ); // 存储图像
break;
case "png" :
imagepng ( $new_img, $dst_file, 100 );
break;
case "gif" :
imagegif ( $new_img, $dst_file, 100 );
break;
default :
break;
}
} else {
// end if 1
// 2 目标图像 的一个边大于原图,一个边小于原图 ,先放大平普图像,然后裁剪
// =if( ($ratio_w < 1 && $ratio_h > 1) || ($ratio_w >1 && $ratio_h <1) )
$ratio = $ratio_h > $ratio_w ? $ratio_h : $ratio_w; //取比例大的那个值
// 定义一个中间的大图像,该图像的高或宽和目标图像相等,然后对原图放大
$inter_w = ( int ) ($w * $ratio);
$inter_h = ( int ) ($h * $ratio);
$inter_img = imagecreatetruecolor ( $inter_w, $inter_h );
//将原图缩放比例后裁剪
imagecopyresampled ( $inter_img, $src_img, 0, 0, 0, 0, $inter_w, $inter_h, $w, $h );
// 定义一个新的图像
$new_img = imagecreatetruecolor ( $new_width, $new_height );
imagecopy ( $new_img, $inter_img, 0, 0, 0, 0, $new_width, $new_height );
switch ($type) {
case "jpg" :
imagejpeg ( $new_img, $dst_file, 100 ); // 存储图像
break;
case "png" :
imagepng ( $new_img, $dst_file, 100 );
break;
case "gif" :
imagegif ( $new_img, $dst_file, 100 );
break;
default :
break;
}
} // if3
} // end function
}
?>
3.图片固定大小及路径设置
<?php
include "../../tools/Image/Image.class.php";
$array = $_FILES['photo'];
//等比例缩放参数
$resizeParam = array (
'imagepath' => 'd:/xampp/www/', //图片存储路径
'imageW' => 200, //图片存储路径
'imageH' => 200 //图片存储路径
);
if (!empty ($array)) {
Image :: getInstance()->uploadresize($array, $resizeParam);
}
?>
4.简单form表单
<html>
<body>
<form action='ImageTools.php' method='post' name='form' enctype="multipart/form-data">
<input type='file' name='photo'>
<input type=submit value='submit'>
</form>
</body>
</html>
over
相关参考:
http://blog.51yip.com/php/645.html
<?php
include_once 'ImageResize.class.php';
date_default_timezone_set('PRC');
class Image {
protected $nameinfo;
protected $InputImageFileExtension;
public static function getInstance() {
static $instance;
if (!isset ($instance)) {
$class = __CLASS__;
$instance = new $class ();
}
return $instance;
}
function uploadresize($fileparam, $imageparam) {
$newW = $imageparam['imageW'];
$newH = $imageparam['imageH'];
$this->nameinfo = explode('.',$fileparam['name']);
//取得图片格式
$this->InputImageFileExtension = $this->nameinfo[1];
//判断是不是给了新的文件名
if(empty($imageparam['imagename'])){
$outputFileName = $this->nameinfo[0];
}else{
$outputFileName = $imageparam['imagename'];
}
//判断路径是否正确
if (!file_exists($imageparam['imagepath'])) {
if(!mkdir($imageparam['imagepath'])){
throw new Exception('image path is wrong');
exit;
}
}
$file_src = $imageparam['imagepath']."/". $outputFileName . "_." . $this->InputImageFileExtension;
// temporary safe image storage
if(file_exists($file_src)){
unlink($file_src);
}
move_uploaded_file($fileparam['tmp_name'], $file_src);
// set image size
$imageResize = new ImageResize();
$imageResize->my_image_resize($file_src,$file_src,$newW,$newH,$this->InputImageFileExtension);
}
}
?>
2.设置图片大小处理类:
<?php
class ImageResize {
/*
* 说明:函数功能是把一个图像裁剪为任意大小的图像,图像不变形
* 参数说明:输入 需要处理图片的 文件名,生成新图片的保存文件名,生成新图片的宽,生成新图片的高
* written by smallchicken
* time 2008-12-18
*/
// 获得任意大小图像,不足地方拉伸,不产生变形,不留下空白
function my_image_resize($src_file, $dst_file, $new_width, $new_height, $type) {
if ($new_width < 1 || $new_height < 1) {
echo "params width or height error !";
exit ();
}
if (! file_exists ( $src_file )) {
echo $src_file . " is not exists !";
exit ();
}
// 图像类型
$support_type = array ("jpg", "png", "gif" );
if (! in_array ( $type, $support_type, true )) {
echo "this type of image does not support! only support jpg , gif or png";
exit ();
}
//Load image
switch ($type) {
case "jpg" :
$src_img = imagecreatefromjpeg ( $src_file );
break;
case "png" :
$src_img = imagecreatefrompng ( $src_file );
break;
case "gif" :
$src_img = imagecreatefromgif ( $src_file );
break;
default :
echo "Load image error!";
exit ();
}
$w = imagesx ( $src_img );
$h = imagesy ( $src_img );
////
if($w < $new_width && $h < $new_height){
// 定义一个中间的临时图像,该图像的宽高比 正好满足目标要求
$inter_w = $w;
$inter_h = $h;
$inter_img = imagecreatetruecolor ( $inter_w, $inter_h );
imagecopy ( $inter_img, $src_img, 0, 0, 0, 0, $inter_w, $inter_h );
// 生成一个以最大边长度为大小的是目标图像$ratio比例的临时图像
// 定义一个新的图像
$new_img = imagecreatetruecolor ( $inter_w, $inter_h );
imagecopyresampled ( $new_img, $inter_img, 0, 0, 0, 0, $inter_w, $inter_w, $inter_h, $inter_h );
switch ($type) {
case "jpg" :
imagejpeg ( $new_img, $dst_file, 100 ); // 存储图像
break;
case "png" :
imagepng ( $new_img, $dst_file, 100 );
break;
case "gif" :
imagegif ( $new_img, $dst_file, 100 );
break;
default :
break;
}
die();
}
////
$ratio_w = 1.0 * $new_width / $w;
$ratio_h = 1.0 * $new_height / $h;
$ratio = 1.0;
// 生成的图像的高宽比原来的都小,或都大 ,原则是 取大比例放大,取大比例缩小(缩小的比例就比较小了)
if (($ratio_w < 1 && $ratio_h < 1) || ($ratio_w > 1 && $ratio_h > 1)) {
if ($ratio_w < $ratio_h) {
$ratio = $ratio_h; // 情况一,宽度的比例比高度方向的小,按照高度的比例标准来裁剪或放大
} else {
$ratio = $ratio_w;
}
// 定义一个中间的临时图像,该图像的宽高比 正好满足目标要求
$inter_w = ( int ) ($new_width / $ratio);
$inter_h = ( int ) ($new_height / $ratio);
$inter_img = imagecreatetruecolor ( $inter_w, $inter_h );
imagecopy ( $inter_img, $src_img, 0, 0, 0, 0, $inter_w, $inter_h );
// 生成一个以最大边长度为大小的是目标图像$ratio比例的临时图像
// 定义一个新的图像
$new_img = imagecreatetruecolor ( $new_width, $new_height );
imagecopyresampled ( $new_img, $inter_img, 0, 0, 0, 0, $new_width, $new_height, $inter_w, $inter_h );
switch ($type) {
case "jpg" :
imagejpeg ( $new_img, $dst_file, 100 ); // 存储图像
break;
case "png" :
imagepng ( $new_img, $dst_file, 100 );
break;
case "gif" :
imagegif ( $new_img, $dst_file, 100 );
break;
default :
break;
}
} else {
// end if 1
// 2 目标图像 的一个边大于原图,一个边小于原图 ,先放大平普图像,然后裁剪
// =if( ($ratio_w < 1 && $ratio_h > 1) || ($ratio_w >1 && $ratio_h <1) )
$ratio = $ratio_h > $ratio_w ? $ratio_h : $ratio_w; //取比例大的那个值
// 定义一个中间的大图像,该图像的高或宽和目标图像相等,然后对原图放大
$inter_w = ( int ) ($w * $ratio);
$inter_h = ( int ) ($h * $ratio);
$inter_img = imagecreatetruecolor ( $inter_w, $inter_h );
//将原图缩放比例后裁剪
imagecopyresampled ( $inter_img, $src_img, 0, 0, 0, 0, $inter_w, $inter_h, $w, $h );
// 定义一个新的图像
$new_img = imagecreatetruecolor ( $new_width, $new_height );
imagecopy ( $new_img, $inter_img, 0, 0, 0, 0, $new_width, $new_height );
switch ($type) {
case "jpg" :
imagejpeg ( $new_img, $dst_file, 100 ); // 存储图像
break;
case "png" :
imagepng ( $new_img, $dst_file, 100 );
break;
case "gif" :
imagegif ( $new_img, $dst_file, 100 );
break;
default :
break;
}
} // if3
} // end function
}
?>
3.图片固定大小及路径设置
<?php
include "../../tools/Image/Image.class.php";
$array = $_FILES['photo'];
//等比例缩放参数
$resizeParam = array (
'imagepath' => 'd:/xampp/www/', //图片存储路径
'imageW' => 200, //图片存储路径
'imageH' => 200 //图片存储路径
);
if (!empty ($array)) {
Image :: getInstance()->uploadresize($array, $resizeParam);
}
?>
4.简单form表单
<html>
<body>
<form action='ImageTools.php' method='post' name='form' enctype="multipart/form-data">
<input type='file' name='photo'>
<input type=submit value='submit'>
</form>
</body>
</html>
over
相关参考:
http://blog.51yip.com/php/645.html
发表评论
-
workerman PHP socket 服务器框架
2015-12-17 14:25 794http://www.workerman.net/ wor ... -
CentOS6.5 下编译安装php-5.6.3.tar.gz
2015-09-15 15:54 2091一、安装相关依赖库 yum -y install gc ... -
php 添加mongodb扩展
2014-04-30 17:03 761PHP MongoDB 扩展安装 [root@a5139 ~] ... -
nginx添加php basic验证
2014-07-16 10:37 603几种方式: 1.命令 http://www.centos.b ... -
使用PHP 给网站 生成快照图片和缩略图
2012-06-07 10:21 1953使用PHP 给网站 生成快 ... -
HTML5 修改浏览器url而不刷新页面
2012-04-05 17:54 2245<?php if(!isset($_REQUEST['p ... -
使用Imagick来”resize” 和 “crop” GIF动画
2012-03-23 19:32 1510http://www.cnblogs.com/analyzer ... -
php bmp图片格式转化png
2012-03-21 13:38 1667有gd库不支持bmp格式的图片缩放,裁剪,所以可以通过改变图片 ... -
crontab执行不了php的解决方法
2012-03-12 18:26 3575用crontab跑php程序时,如 ... -
php mongodb 实现group 并按照某字段排序
2012-02-27 17:13 7676require_once ('../Config.class. ... -
php 国际化
2012-02-16 18:47 1400PHP的gettext用法 gettext ... -
php报错启动配置
2011-10-13 13:32 2191PHP 报错信息 2008年11月22 ...
相关推荐
C#字符串截取固定长度的方法
可以对照片进行缩放,缩放后,截取固定大小的圆形图片,可作为头像。
js获得字符真实长度,如果长度超过len值,js截取固定长度字符
这个工具不仅可以截取图片,还可以确定图片尺寸大小,还可以截取颜色等功能,非常强大。
.net上传图片并在线截取图片,网页中上传图片并截取图片大小,跟QQ上传头像,并截取大小类似
jquery 上传图片时截取固定大小的范围图片 类似QQ上传头像截取,17年用的了 当时亲自测试用过还不错
本文实例讲述了PHP截取指定图片大小的方法。分享给大家供大家参考。具体分析如下: imagecopyresampled($newim, $im, 0, 0, 7, 174, 120, 42, $new_img_width, $new_img_height); // 原始尺寸 120 x 42 ...
jquery上传 图片预览 截取图片大小
java 处理图片大小等比例缩放;图片裁剪;支持图片压缩不失真;支持图片添加水印;支持动态图的处理;支持自定义图片大小的转换 等 压缩包中内附使用说明
上传图片并在线截取 php上传图片并托动截取
在图上移动和改变选框的大小,通过JavaScript实现截取该选框内部的图像选区,并且把选框的长宽,选框距离各个边框的位置,动态的显示出来,实现用户根据需要截取一张大图的局部。
PHP 去HTML,截取指定汉字正则表达试PHP 去HTML,截取指定汉字正则表达试PHP 去HTML,截取指定汉字正则表达试PHP 去HTML,截取指定汉字正则表达试PHP 去HTML,截取指定汉字正则表达试PHP 去HTML,截取指定汉字正则表达试...
c#截取一张图片的部分 或者缩放图片,教你如何加工原始的图片,变成你想要的效果
通过jquery的两个插件实现图片截取效果,上传 后台实现图片根据截取出来的位置坐剪切 压缩 可以配合图片缓存的数据库做的接口实现图片服务器做iframe 跨域上传
使用java applet开发,指定要截取的屏幕范围,保存成图片到客户端的小应用程序。
js 截取图片代码
高仿微信demo,内含截取本地图片,截取手机拍照图片作为头像
jquery图片截取DEMO,jquery图片截取DEMO
ffmpeg-php-win32-all.zip 视频截取图片