php修改上传图片尺寸的方法

本文实例讲述了php修改上传图片尺寸的方法。分享给大家供大家参考。具体实现方法如下:

<?php
// This is the temporary file created by PHP
$uploadedfile = $_FILES['uploadfile']['tmp_name'];
// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);
// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);
// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
$newwidth=600;
$newheight=($height/$width)*600;
$tmp=imagecreatetruecolor($newwidth,$newheight);
// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = "images/". $_FILES['uploadfile']['name'];
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
// NOTE: PHP will clean up the temp file it created when the request
// has completed.
?>

希望本文所述对大家的php程序设计有所帮助。

(0)

相关推荐

  • android上传图片到PHP的过程详解

    今天在做上传头像的时候,总是提交连接超时错误,报错信息如下:XXXXXXSokcetTimeOutXXXXXXXX 然后自己设置HTTP的超时时间: 复制代码 代码如下: [java] view plaincopyprint? //设置超时时间  httpclient.setTimeout(20000); 再building,runing,还是不行....这就怪了,明明好好的,怎么会突然就变成连接超时了呢!又折腾了一阵子后,也跟后台那边的朋友沟通过,他也测试了上传接口,发现没什么问题,就让我自己

  • Android异步上传图片到PHP服务器

    原理 Android客户端模拟一个HTTP的Post请求到服务器端,服务器端接收相应的Post请求后,返回响应信息给给客户端. 背景 网上很多上传到java服务器上的,找了好久,找到了上传到php的了,思路跟我当初想的差不多,就是POST过去.废话不多说,直接上图看代码. php代码 <?php $target_path = "./upload/";//接收文件目录 $target_path = $target_path . basename( $_FILES['uploaded

  • php上传图片生成缩略图(GD库)

    首先来一段简单的php上传图片生成缩略图的详细代码,分享给大家供大家参考,具体内容如下 <?php function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality){ $details = getimagesize("$imageDirectory/$imageName") or die('Please only upload images.'); $type

  • PHP 中 Orientation 属性判断上传图片是否需要旋转

    当使用苹果的iOS系统拍照上传图片的时候,可能会遇到图片被旋转的问题,这主要是取决于你拍照时拍照按钮的位置.假设拍照时你把手机旋转过来底部朝上,那拍出来的照片也是被旋转了的. 下面的代码将确保所有上传的照片在上传时都能是正确定向: <?php $image = imagecreatefromstring(file_get_contents($_FILES['image_upload']['tmp_name'])); $exif = exif_read_data($_FILES['image_up

  • PHP上传图片、删除图片简单实例

    简单PHP上传图片.删除图片实现代码 上传图片: if (!empty($_FILES["img"]["name"])) { //提取文件域内容名称,并判断 $path="uppic/"; //上传路径 if(!file_exists($path)) { //检查是否有该文件夹,如果没有就创建,并给予最高权限 mkdir("$path", 0700); }//END IF //允许上传的文件格式 $tp = array(&qu

  • thinkphp3.2实现上传图片的控制器方法

    本文讲述了thinkphp3.2实现上传图片的控制器方法.分享给大家供大家参考,具体如下: public function file() { $baseUrl = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])); import('ORG.Net.UploadFile'); import('ORG.Util.Services_JSON'); $upload = new UploadFile(); $upload->maxSize =

  • PHP上传图片时判断上传文件是否为可用图片的方法

    本文实例讲述了PHP上传图片时判断上传文件是否为可用图片的方法.分享给大家供大家参考,具体如下: 这里利用getimagesize函数: function isImage($filename) { $types = '.gif|.jpeg|.png|.bmp'; //定义检查的图片类型 if(file_exists($filename)) { $info = getimagesize($filename); $ext = image_type_to_extension($info['2']);

  • php+html5+ajax实现上传图片的方法

    本文实例讲述了php+html5+ajax实现上传图片的方法.分享给大家供大家参考,具体如下: <?php if (isset($_POST['upload'])) { var_dump($_FILES); move_uploaded_file($_FILES['upfile']['tmp_name'], 'up_tmp/'.time().'.dat'); //header('location: test.php'); exit; } ?> <!doctype html> <

  • php实现上传图片文件代码

    代码很简单,这里我们就不多废话了,直接奉上源码 <?php // 注册表单的姓名 $name=""; $nameErr=""; if ($_SERVER["REQUEST_METHOD"]=="POST") { if (empty($_POST['name'])) { }else{ $name=$_POST['name']; if (!preg_match("/^[a-zA-Z]*$/", $name

  • php修改上传图片尺寸的方法

    本文实例讲述了php修改上传图片尺寸的方法.分享给大家供大家参考.具体实现方法如下: <?php // This is the temporary file created by PHP $uploadedfile = $_FILES['uploadfile']['tmp_name']; // Create an Image from it so we can do the resize $src = imagecreatefromjpeg($uploadedfile); // Capture

  • jQuery在页面加载时动态修改图片尺寸的方法

    本文实例讲述了jQuery在页面加载时动态修改图片尺寸的方法.分享给大家供大家参考.具体如下: $(window).bind("load", function() { // IMAGE RESIZE $('#product_cat_list img').each(function() { var maxWidth = 120; var maxHeight = 120; var ratio = 0; var width = $(this).width(); var height = $(

  • java实现上传图片尺寸修改和质量压缩

    本文实例为大家分享了java实现上传图片尺寸修改和质量压缩的具体代码,供大家参考,具体内容如下 package com.zity.frame.util;   /**    *  缩略图实现,将图片(jpg.bmp.png.gif等等)真实的变成想要的大小    */   import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGImageEncoder; import net.sourceforg

  • python批量修改图片尺寸,并保存指定路径的实现方法

    如下所示: import os from PIL import Image filename = os.listdir("D:\\Work\\process\\样本处理\\polyu-all-train") base_dir = "D:\\Work\\process\\样本处理\\polyu-all-train\\" new_dir = "D:\\Work\\process\\样本处理\\polyu\\" size_m = 128 size_n

  • Python修改游戏内存的方法

    目录 前言 游戏的安装 思路 一句话总结 大概的思路 实战 确定修改哪一款游戏的数据 代码 地址的寻找 视频教程 修改数据 代码 效果 完整的源码 所有的软件下载包 前言 大家好,我叫善念.上篇文章我许了一个愿,就是想让大家多多关注我,然后我的粉丝就蹭蹭的涨了好几百,谢谢大家的厚爱.可是我发现粉丝是涨了,三连变少了,谢谢大家这次给我三连,我一定再接再厉.有问题留在评论区,我会一一回复,谢谢大家! 这次要做的是修改一款单机游戏的数据,学过C语言的朋友肯定经常会看到有些老师讲这个案例,就是<植物大战

  • MAC下Mysql5.7.10版本修改root密码的方法

    首先 跳过权限表模式启动MySQL:mysqld --skip-grant-tables & 从现在开始,你将踏入第一个坑,如果你使用网上到处贴的 错误修改方法: mysql> UPDATE mysql.user SET authentication_string=PASSWORD('your_new_password') WHERE User='root'; (注意,5.7之后password改成了authentication_string)那么恭喜你,你修改成功了,但是你会发现当你使用n

  • 关于SQL Server 2008忘记sa密码修改sa密码的方法图解

    1. 先用Window身份验证方式登陆进去,选择数据库实例,右键选择属性--安全性:把服务器身份验证选项从"Window身份验证模式"改为"SQLServer和Window身份验证模式".点击确定,关闭当前对象资源管理器.   2. 重 新用Window验证方式登陆,在左边的树结构中选择"数据库"下面的"安全性"选项--登录名--sa,右键属性--在"SQLServer身份验证"中输入要设置的sa密码. 3

  • Centos下 修改mysql密码的方法

    1.修改MySQL的登录设置: # vim /etc/my.cnf 加上一句:skip-grant-tables 如: [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock 2.重启mysql # service mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK ] 3.修改密码 mysql> USE mysql ; Database changed m

  • Linux下刚安装完mysql修改密码的简单方法

    在Centos中安装MySQL后默认的是没有root密码的,默认的是回车, 那么为了方便需要修改密码. 没有密码为MYSQL加密码: mysql -uroot -p 回车 提示输入密码,为空回车 update mysql.user set password=PASSWORD('12345678') where user='root'; 刷新权限表,输入如下命令 flush privileges; 退出 quit 以上所述是小编给大家介绍的Linux下刚安装完mysql修改密码的简单方法,希望对大

随机推荐