JImage to create thumbnails for some images in a component, with a code similar to this:
// Set the desired sizes for our thumbnails. $sizes = array('300x300'); // Create our object $image = new JImage(JPATH_SITE . '/path/to/image.png'); // Create the thumbnails $image->createThumbs($sizes, JImage::SCALE_INSIDE);
Because all my images have landscape format, this creates thumbnails with a width of 300px and varying height, inside the
thumbs subfolder, and the name is a combination of the original name and the resulting size, e.g.
But how can I get the thumbnail image name in order to display it? From the component parameters I get the name of the original image, but the thumbnail name will depend on the aspect ratio of the original image, and I can only be sure of the first part (
I guess I can list all images in the
thumbs folder, and check for file names containing the original name, but I'm hoping there are simpler ways to do this.