I'm trying to implement an image gallery with GWT. My intention is to show a list of albums, when you click on one of them show a grid with the photo's thumbnails on it and, when you click on one of them, show the full-size image in a popup window. I've succeeded on the first and last points, but I'm getting a lot of problems building the thumbnails.
My idea is to have squared, fixed size thumbnails. To do so, I try to scale and then crop them. But it doesn't work. If I only scale them it works, if I only crop them it works, but when I try to scale&crop only the last operation is executed. This is what I coded to do that:
prop = (float)img.getWidth() / img.getHeight();
thumb = new Image(img.getUrl());
if (thumb.getWidth() > thumb.getHeight()) {
thumb.setHeight("150px");
thumb.setWidth(String.valueOf(150 * prop) + "px");
} else {
thumb.setWidth("150 px");
thumb.setHeight(String.valueOf(150 * Prop) + "px");
}
offset = thumb.getHeight()*(prop-1) / 2;
if (thumb.getWidth() > thumb.getHeight()) {
thumb.setVisibleRect((int)offset, 0, 150, 150);
} else {
thumb.setVisibleRect(0, (int)offset, 150, 150);
}
I've been looking for help about this and I found several solutions. Based on another question in this website I found this, but it's not applicable to my case, because I need to load the images dinamically. I also tried with GWT and HTML5, following this example, but when the following method is executed:
ImageData imageData = context.getImageData(sx, sy, sw, sh);
it raises the following exception:
(NS_ERROR_DOM_INDEX_SIZE_ERR): Index or size is negative or greater than the allowed amount
So, if anyone knows how to do it with pure GWT, or solve de HTML5 error, I will be very pleased, I've been stuck on this for many weeks :(... thanks in advance!