Javascript/PHP : upload resized images first, 大文件稍后

标签 javascript php image upload resize

我正在编写这个设计应用程序,用户需要上传图像。如果客户端可以先上传图像的缩略图,从而允许用户在上传真实图像之前开始工作,那就太好了。 (仅在稍后导出设计时才需要它们。)

我简单地浏览了一些允许调整大小的软件包,但它们似乎同时上传缩略图和图像,从而阻止用户快速获得缩略图。

是否可以创建文件上传,以便首先上传调整大小的图像,然后然后真实(全尺寸)图像?

谢谢, --凯杰尔

最佳答案

试试这个:

$pathToThumbs = "path/to/thumbs";

$new_fname = "thumb-file-name";
$img = imagecreatefromjpeg( imagecreatefromjpeg($_FILES['uploaded_file']['tmp_name']) );

$width = imagesx( $img );
$height = imagesy( $img );
$thumbWidth = //someValue//;
$thumbHeight = //someValue//;
$new_height = floor($height * ($thumbWidth/$width));
$new_width = $thumbWidth;
$tmp_img = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width,$new_height, $width, $height );

move_uploaded_file( $tmp_img, "{$pathToThumbs}{$new_fname}" );

关于Javascript/PHP : upload resized images first, 大文件稍后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20783154/

相关文章:

android - 突出显示图像上的文字,类似于谷歌翻译应用程序

javascript - build 和 dist 文件夹有什么区别?

javascript - 如何使用 Angularjs 重新加载页面?

php - 插入多数据库建模

php - 如何计算 PHP Web 应用程序中的在线用户数?

php - 从多维数组中的元素获取最大值?

javascript - 错误:在 Ember.js 服务器上获取 http://localhost:4200/assets/vendor.js net::ERR_INVALID_CHUNKED_ENCODING

javascript - 使用正则表达式匹配相对图像 URL,然后使用字符串替换使用 Javascript 将其设为绝对 URL

Javascript简单图像 slider

html - 使图像在特定位置可点击