我环顾了一会儿,发现了一些我无法工作的非常令人困惑和复杂的东西。
我正在使用带有joomla的chronoforms来创建一个带有上传文件脚本的表单,并且它将图像上传到服务器没有任何问题,到目前为止一直很好。
我需要上传图像并调整大小,更好的是,有没有办法在将图像上传到服务器之前调整图像大小?
感谢。
答案 0 :(得分:15)
答案 1 :(得分:1)
我已经将PHPThumb用于我的一些项目,并且发现它很容易使用并且资源占用空间很小。您可以阅读文档以获取更多信息,但这很简单:
$thumb = PhpThumbFactory::create('/path/to/source/image.png');
$thumb->resize(100, 100);
$thumb->save('/path/where/you/want/resized/image.png');
答案 2 :(得分:0)
查看此链接。很简单:
答案 3 :(得分: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);
?>
答案 4 :(得分:0)
Chronoforms(此处为第4版)确实支持开箱即用! (我已经看到旧版本的随机痕迹,低至1.3。)
我可以将Image Resize
操作(从Utilites
下方)拖到所需的表单事件(On Submit
下)。
注意:对于客户端调整大小,不。为此,您需要一个Javascript表单上传程序包,它可以在&amp;之前显示缩略图。在上传过程中。它们通常是非平凡的整合。 (并且使用那些客户端缩略图也用于上传以及原始图像需要一些更高级的 - 并且因此更复杂 - 的东西;我会说它很少值得额外的痛苦,只是咬紧牙关并在服务器上再次生成缩略图,并考虑所有那些可怜的非洲孩子,他们的生活比网络开发者更艰难。))
答案 5 :(得分:0)
这是我创建的一个简单的调整大小库,可以在here on Github找到。
适用于任何框架。
如何使用该库的示例:
// Include PHP Image Magician library
require_once('php_image_magician.php');
// Open JPG image
$magicianObj = new imageLib('racecar.jpg');
// Resize to best fit then crop (check out the other options)
$magicianObj -> resizeImage(100, 200, 'crop');
// Save resized image as a PNG (or jpg, bmp, etc)
$magicianObj -> saveImage('racecar_small.png');