如何在 blueimp jquery fileupload 中设置缩略图大小?

How can i set the thumbnail size in blueimp jquery fileupload?

这太疯狂了,但我没能做到 google。

我的电话:

$('.fileupload').fileupload({
    dataType: 'json',
    done: function(e, data) {
        $.each(data.result.files, function(index, file) {
            // do something with file and index
        });
    }
});

应该有个设置缩略图大小的选项吧?

提前致谢

你说的是显示上传图片的高度还是宽度的形式?

更改上传的img width/height 非常简单: 您将在以下位置找到最多选项:

./server/php/UploadHandler.php

您可以在第 146 行

上更改上传的 img 的大小
        'thumbnail' => array(
            // Uncomment the following to use a defined directory for the thumbnails
            // instead of a subdirectory based on the version identifier.
            // Make sure that this directory doesn't allow execution of files if you
            // don't pose any restrictions on the type of uploaded files, e.g. by
            // copying the .htaccess file from the files directory for Apache:
            //'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'/thumb/',
            //'upload_url' => $this->get_full_url().'/thumb/',
            // Uncomment the following to force the max
            // dimensions and e.g. create square thumbnails:
            //'crop' => true,
            'max_width' => 205,
            'max_height' => 155 
        )

将文件重定向到您自己的上传服务器端脚本:

$('#fileupload').fileupload({
        url: 'my_uploader.php',
        dataType: 'json',
        ...
});

设置 UploadHandler 对象的选项。传入图像的所有调整大小的版本(甚至不止一个!)都可以在那里配置。

my_uploader.php:

<?php
include "lib/jQuery-File-Upload/server/php/UploadHandler.php";

$options = array(
    'upload_dir'=>'photo/',
    'upload_url'=>'photo/',

    'image_versions' => array(
                '' => array(), // original

                'medium' => array(
                    'max_width' => 800,
                    'max_height' => 800
                ),
                'thumbnail' => array(
                    'crop' => true,
                    'max_width' => 300,
                    'max_height' => 300
                )
            )
    );
$upload_handler = new UploadHandler($options);
?>