Hi
I've used the ImageGallery module in a site where content is driven by a client. We had an issue with content managers uploading images that were smaller than "NormalSize" with the result that the resampled images were larger than the original image... resulting in poor quality "downsampled" images.
I couldn't find a solution to this via Google or config option, so came up with a simple solution to use SetSize, not SetWidth/SetHeight if the original image is smaller than NormalSize in the required dimension.
Code ( - is removed code, + is added code from my version control diff)
- if($item->Image()->Landscape())
- $normalImg = $item->Image()->SetWidth($this->NormalSize);
- else
- $normalImg = $item->Image()->SetHeight($this->NormalSize);
-
+ $normalImg = $this->normalImg($item);
and added a normalImg() method to ImageGalleryPage (to retain the default behaviour)
+ protected function normalImg($item) {
+ if($item->Image()->Landscape()) {
+ return $item->Image()->SetWidth($this->NormalSize);
+ } else {
+ return $item->Image()->SetHeight($this->NormalSize);
+ }
+ }
and then override this new method in my own page that extends ImageGalleryPage:
+ /**
+ * normalImg() override ImageGalleryPage normalImg handling
+ * @note if the image is less than the configured normal width set in the admin, then use the original image size
+ * @param $item the gallery image
+ */
+ protected function normalImg($item) {
+ $width = $item->Image()->getWidth();
+ $height = $item->Image()->getHeight();
+ if($item->Image()->Landscape()) {
+ if($width < $this->NormalSize) {
+ return $item->Image()->SetSize($width, $height);
+ } else {
+ return $item->Image()->SetWidth($this->NormalSize);
+ }
+ } else {
+ if($height < $this->NormalSize) {
+ return $item->Image()->SetSize($width, $height);
+ } else {
+ return $item->Image()->SetHeight($this->NormalSize);
+ }
+ }
+ }
Maybe this could be merged back into the core module code? A configuration option "do not upsize/downsample images" would be useful as well.
Code could be optimised if required but it works.
Thanks
James
Edit - should be some tabs in that code but the forum seems to be removing them