php简单图片上传后调整大小

Man*_*023 5 php joomla resize image

我环顾了一会儿,发现了一些我无法工作的非常混乱和复杂的东西.

我正在使用带有joomla的chronoforms来创建一个带有上传文件脚本的表单,并且它将图像上传到服务器没有任何问题,到目前为止一切顺利.

我需要上传图像并调整大小,更好的是,有没有办法在将图像上传到服务器之前调整图像大小?

谢谢.

Nim*_*007 15

我使用这个简单的1功能来完成所有工作

看看这个 :

http://www.nimrodstech.com/php-image-resize/

https://github.com/Nimrod007/PHP_image_resize


Her*_*err 0

[此示例] 是您正在寻找的imagecopyresampled

<?php
// The file
$filename = 'test.jpg';
$percent = 0.5;

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

// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;

// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Output
imagejpeg($image_p, null, 100);
?>
Run Code Online (Sandbox Code Playgroud)

  • @FlyingGuy - 答案尚未编辑,所以我不知道你在说什么,但这是唯一的本机 PHP 图像库 (GD),并且它会在传输之前对图像进行重新采样。事实上,这个答案与客户端完全无关。所以..你在说什么? (2认同)