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

Latest versions not working with AWS media source #111

Open
matdave opened this issue Jul 27, 2022 · 4 comments
Open

Latest versions not working with AWS media source #111

matdave opened this issue Jul 27, 2022 · 4 comments
Labels

Comments

@matdave
Copy link

matdave commented Jul 27, 2022

Upgrading from 2.8.5 to 2.9.1 caused it to stop working with AWS media sources. When I select the image from an AWS Source it says image could not be found. It looks like it is trying to read the path and not the full URL.

@Jako
Copy link
Owner

Jako commented Jul 27, 2022

I currently have no external media source available. This code tries to get the image size with img.onload, since the MODX way has issues with images larger than 800x600. With 2.9.1 I did not use the MODX way anymore and switched to the img.onload:

getImageSize: function (changed, callback, scope) {
var baseUrl = ImagePlus.config.sources[this.image.sourceImg.source].url;
var img = new Image();
img.onload = (function (ths) {
return function () {
ths.image.sourceImg.width = this.width;
ths.image.sourceImg.height = this.height;
ths.oldSource = ths.image.sourceImg.src;
// Reset crop rectangle everytime an image is changed
if (changed) {
ths.image.crop.x = 0;
ths.image.crop.y = 0;
if (ths.options.targetRatio) {
if (ths.image.sourceImg.width / ths.image.sourceImg.height < ths.options.targetRatio) {
ths.image.crop.width = ths.image.sourceImg.width;
ths.image.crop.height = Math.ceil(ths.image.sourceImg.width / ths.options.targetRatio);
} else {
ths.image.crop.width = Math.ceil(ths.image.sourceImg.height / ths.options.targetRatio);
ths.image.crop.height = ths.image.sourceImg.height;
}
} else {
ths.image.crop.width = ths.image.sourceImg.width;
ths.image.crop.height = ths.image.sourceImg.height;
}
}
if (typeof callback === 'function') {
callback(scope);
}
}
})(this);
img.onerror = (function (ths) {
return function () {
if (!ths.oldSourceImg) {
ths.imageBrowser.reset();
} else {
for (var i in this.oldSourceImg) {
ths.image.sourceImg[i] = this.oldSourceImg[i];
}
if (ths.oldSourceImg.crop) {
ths.image.crop.x = ths.oldSourceImg.crop.x;
ths.image.crop.y = ths.oldSourceImg.crop.y;
ths.image.crop.width = ths.oldSourceImg.crop.width;
ths.image.crop.height = ths.oldSourceImg.crop.height;
}
ths.imageBrowser.setValue(ths.oldSource || '');
}
MODx.msg.alert(_('imageplus.error.image_not_found.title'), _('imageplus.error.image_not_found.msg'));
return false;
}
})(this);
img.src = baseUrl + this.image.sourceImg.src;
},
.

There has to be some switch for external media sources.

@Jako Jako added the bug label Jul 27, 2022
@matdave
Copy link
Author

matdave commented Aug 2, 2022

Ah, on external media i stopped grabbing the image dimensions with the media source because it's huge request killer when there are more than a handful of files in a folder.

@matdave
Copy link
Author

matdave commented Aug 2, 2022

@Jako
Copy link
Owner

Jako commented Aug 7, 2022

The issue is the onload requirement. An external media source has to retrieve the image different. If you are able to send me some code loading the image from an exernal media source I will be very happy.

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

No branches or pull requests

2 participants