我正在编写这个设计应用程序,用户需要上传图像。如果客户端可以先上传图像的缩略图,从而允许用户在上传真实图像之前开始工作,那就太好了。 (仅在稍后导出设计时才需要它们。)
我简单地浏览了一些允许调整大小的软件包,但它们似乎同时上传缩略图和图像,从而阻止用户快速获得缩略图。
是否可以创建文件上传,以便首先上传调整大小的图像,然后然后真实(全尺寸)图像?
谢谢, --凯杰尔
最佳答案
试试这个:
$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/