当前位置: 首页 > 编程笔记 >

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

方璞
2023-03-14
本文向大家介绍php修改上传图片尺寸的方法,包括了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程序设计有所帮助。

 类似资料:
  • Many web-developers forget to write width and height attributes for <img> tags which leads to poor UX. This action helps you to automate this process: simply place caret inside <img> tag and run this

  • Icon与图片尺寸 每个应用都需要一个漂亮的、令人难忘的主屏幕图标,以便用户可以很好地识别应用程序。由于用户仅仅通过主屏幕上的icon识别应用程序,所以你的icon应当是可辨认的,并且类似iOS应用程序的icon,并且能传达出应用程序的目的。 Icon尺寸 主屏幕上的icon是圆形的。Table 20-1列出了每个icon相应的直径和用途。所创建的图形资源都是@2x规格(注意:Xcode中的ico

  • 本文向大家介绍上传图片js判断图片尺寸和格式兼容IE,包括了上传图片js判断图片尺寸和格式兼容IE的使用技巧和注意事项,需要的朋友参考一下 js代码: css代码(这个是必须写的,如果不写,ie下不起作用) html代码:

  • 有没有办法在不拉伸位图的情况下增加位图的宽度(或高度)?基本上,我有一个200x100的位图,我想通过在左侧附加50个(白色/透明)像素,在右侧附加50个像素,使其成为正方形(200x200)。 我不想在屏幕上画这个位图,所以,理想情况下,我应该以“聪明”的方式使用转换矩阵或类似的东西,但是我就是想不出来...

  • 本文向大家介绍PHP结合Ueditor并修改图片上传路径,包括了PHP结合Ueditor并修改图片上传路径的使用技巧和注意事项,需要的朋友参考一下 前言 在使用UEditor编辑器时,一般我们都是需要修改默认的图片上传路径的,下面是我整理好的修改位置和方法供大家参考。 操作 Ueditor PHP版本本身自带了一套上传程序,我们可以在此基础中,找到配置文件修改它。配置文件位置: ueditor/p

  • 本文向大家介绍matplotlib 输出保存指定尺寸的图片方法,包括了matplotlib 输出保存指定尺寸的图片方法的使用技巧和注意事项,需要的朋友参考一下 其实这个问题来源于笔者的横坐标太多了,然后生成的那个figure框框太小,导致坐标重叠,而输出的图片是需要批量保存的,总不能每次都拉长截图吧 所以在plot绘图之前加上了一句 图就变了hhh 然后偶然间有发现了能调节子图也就是subplot