4

HTML5 Resize image before upload without ajax

 2 years ago
source link: https://gist.github.com/dragermrb/6d4b7fda5f183524d0ebe4b0a7d8635c
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

HTML5 Resize image before upload without ajax

Allows to resize a file input image before upload to the server. The resized image will be attached to original file input. Then you can submit your form without ajax or handle it as you need.

Usage as jQuery Plugin

<form>
    <label>Select image</label>
    <input type="file" id="media_file" name="media_file" accept="image/*" capture="camera" class="form-control-file">

    <input type="submit" value="Upload"/>
</form>

<script src="js/jquery.min.js"></script>
<script src="js/jquery-image-upload-resizer.js"></script>
<script>
    $('#media_file').imageUploadResizer({
        max_width: 800, // Defaults 1000
        max_height: 600, // Defaults 1000
        quality: 0.8, // Defaults 1
        do_not_resize: ['gif', 'svg'], // Defaults []
    });
</script>

Usage as Vue Component

<form>
    <label>Select image</label>
    <image-upload-resizer-component
        name='media_file'
        :max-width="512"
        :max-height="512"
        :class-name="['form-control-file']"
        accept="image/*"
        capture="camera"
        doNotResize="['gif', 'svg']"
    ></image-upload-resizer-component>

    <input type="submit" value="Upload"/>
</form>

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK