Skip to content

Conversation

@ArcRain
Copy link

@ArcRain ArcRain commented Feb 1, 2018

When we load one thumbnail for image, we want to know the original image size same time. I found the 2nd param in callback get image extra info. So I add a new property in default object.

When we load one thumbnail for image, we want to know the original image size same time.
@blueimp
Copy link
Owner

blueimp commented Feb 2, 2018

Thanks for your contribution, @ArcRain

The loadImage function returns the original image (see API doc), which you can use to retrieve any HTMLImageElement property:

var loadingImage = loadImage(
  'https://blueimp.github.io/Gallery/img/loading.gif',
  function callback (img) {
    console.log(loadingImage.naturalWidth, loadingImage.naturalHeight)
  },
  { maxWidth: 100, canvas: true }
)

Do you have any use case that cannot make use of that return value?

@ArcRain
Copy link
Author

ArcRain commented Feb 2, 2018

I haven’t noticed the return value. You’re right, it’s a good way to retrieve img property.
I just think we can get more about original image info from result in callback function.

@blueimp
Copy link
Owner

blueimp commented Feb 3, 2018

Ok, unless you have a solid use case that prevents you from using the return value, I'd prefer to not merge this pull request.
Thanks for your understanding.

@ArcRain
Copy link
Author

ArcRain commented Feb 4, 2018

That's OK. Thanks for your reply. :-)

@ArcRain ArcRain closed this Feb 4, 2018
@blueimp
Copy link
Owner

blueimp commented Feb 5, 2018

btw. if you definitely want to have the natural image properties in the callback, you can wrap the function like this:

function customLoadImage(file, callback, options) {
  var loadingImage = loadImage(
    file,
    function customCallback (img, data) {
      data = data || {}
      data.naturalWidth = loadingImage.naturalWidth
      data.naturalHeight = loadingImage.naturalHeight
      callback(img, data)
    },
    options
  )
  return loadingImage
}

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

Successfully merging this pull request may close these issues.

2 participants