比例图像调整大小 [英] Proportional image resizing

查看:96
本文介绍了比例图像调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将上传的图片调整为宽度:180px,比例高度。是否有任何课程要做?

i want to resize uploaded images to width: 180px with proportional height. Is there any classes to do this?

感谢您的帮助!

推荐答案

我认为这个问题可以使用实际代码示例的答案。下面的代码显示了如何在目录上传内调整图像大小,并将调整后的图像保存在文件夹 resized

I think this question can use an answer with an actual code example. The code below shows you how you to resize an image inside a directory uploaded, and save the resized image in the folder resized.

<?php
// the file
$filename = 'uploaded/my_image.jpg';

// the desired width of the image
$width = 180;

// content type
header('Content-Type: image/jpeg');

list($width_orig, $height_orig) = getimagesize($filename);

$ratio_orig = $width_orig/$height_orig;
$height = $width/$ratio_orig;

// resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// output
imagejpeg($image_p, 'resized/my_image.jpg', 80);
?>

这篇关于比例图像调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆