Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black border when resizing on iPhone Safari #1337

Closed
6 of 18 tasks
edwh opened this issue Dec 5, 2018 · 6 comments
Closed
6 of 18 tasks

Black border when resizing on iPhone Safari #1337

edwh opened this issue Dec 5, 2018 · 6 comments

Comments

@edwh
Copy link

edwh commented Dec 5, 2018

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of bootstrap-fileinput. (I'm on 4.5.1 which is very recent)
  • This is not an usage question. I confirm having read the plugin documentation and demos.
  • This is not a general programming / coding question. (Those should be directed to the webtips Q & A forum).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional).

Steps to reproduce the issue

  1. Use iPhone Safari
  2. Use resizeImage: true, maxImageWidth: 800.

Expected behavior and actual behavior

Get a resized photo which looks ok.

When I follow those steps, I see a black border on the image:

image

I've got the image here by dumping the image posted to the server.

I was expecting no black border, i.e. appropriate image dimensions.

Environment

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version: 3.3.1
  • bootstrap-fileinput version: 4.5.1

Isolating the problem

  • This bug happens on the plugin demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using bootstrap-fileinput without other plugins
  • I can reproduce this bug in a jsbin

I can only repro this on an iPhone using Safari.

@kartik-v
Copy link
Owner

kartik-v commented Dec 6, 2018

This is due to an iOS restriction / bug / behavior where it subsamples images over 2Megapixels. According to this link, JPEG files over 2M pixels will be subsampled.

Will check later on this when I get time.

@edwh
Copy link
Author

edwh commented Dec 8, 2018 via email

@fstrahberger
Copy link

Hello Edward,
here is a solution that helped me solve this problem:

$("#upload_files").fileinput({
        language: 'de',
        previewFileType: "image",
        maxFileCount: 20,
        autoOrientImage: true,
        // maxImageHeight: 1200,
        // maxImageWidth: 1200,
        // resizePreference: 'width',
        // resizeImage: true,
        browseClass: "btn btn-success",
  • resize the images in fileimagesloaded event (get files from stack, clear stack , refill stack with modified images)
$('#upload_files').on('fileimagesloaded ', function(event) {
    var myFiles = $('#upload_files').fileinput('getFileStack');
    $('#upload_files').fileinput('clearStack');

    var imgList = [];
    for (i = 0; i < myFiles.length; i++) {
       let item = {
            mpimg: new MegaPixImage(myFiles[i]),
            file: myFiles[i]
        };
        imgList.push(item);
    }

    imgList.forEach(function(item) {
         var c = document.createElement("canvas");
         item.mpimg.render(c, { maxWidth: 1200, maxHeight: 1200 }, function(i){
             c.toBlob(function(blob){
                 blob.lastModifiedDate = item.file.lastModifiedDate;
                 blob.name = item.file.name;
                 blob.type = item.file.type;
                 $('#upload_files').fileinput('addToStack', blob);
             }, item.file.type, 0.75);
         });
    });
});

@edwh
Copy link
Author

edwh commented Dec 21, 2018 via email

@silentcossack
Copy link

I can confirm this bug.
This only happens when taking a photo on iPhone in portrait mode. Landscape photos are fine. I believe the code does not properly detect image orientation and resizes improper dimensions.

@kartik-v
Copy link
Owner

The orientation validation specific to iOS safari browser would be resolved by #1362.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants