Closed ArcRain closed 6 years ago
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?
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.
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.
That's OK. Thanks for your reply. :-)
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
}
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.