VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: EvanGR on September 24, 2018, 09:28:13 AM

Title: [SOLVED] Image resize, more variations
Post by: EvanGR on September 24, 2018, 09:28:13 AM
Hello,

Virtuemart, by default, offers a single fixed resolution image resize for thumbnails. Have you (the devs) considered including more variations in the future?

With the use of the <picture> element, one can now define multiple resolutions for an image in the browser.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture

Thanks
Title: Re: Image resize, more variations
Post by: StefanSTS on September 24, 2018, 09:42:43 AM
VirtueMart has a function to resize the images as per your need.

If you need more resolutions you can adjust your template accordingly. Just check the productdetails view.

You find this in the files:

echo $image->displayMediaThumb("",true,"rel='vm-additional-images'", true, true, false, $width, $height);

Stefan
Title: Re: Image resize, more variations
Post by: EvanGR on September 24, 2018, 11:45:38 AM
Hello and thanks.

Does this create additional thumbnails in the images folder?
If so, are they re-used next time, if found by subsequent page loads?

Thanks
Title: Re: Image resize, more variations
Post by: StefanSTS on September 24, 2018, 11:57:59 AM
They will be in the resized/ folder and will be re-used.
Title: Re: Image resize, more variations
Post by: EvanGR on September 26, 2018, 12:13:05 PM
Thanks again.

How can I tweak this code so that I just generate and use the thumbnail filename, but not display it? (VM creates its own img element)

I like to construct my own custom <img /> elements, with additional lazy-loading code and utilizing the <picture> element for image sets.
Title: Re: Image resize, more variations
Post by: StefanSTS on September 26, 2018, 18:08:27 PM
Hi,

never did it that way, but I guess you could call the function for a variable instead of echo'ing it.

$myhiddenimages = $image->displayMediaThumb(... $width, $height);

The thumbs should be generated then and you can access them by name. As I said, I never tried it. Maybe keep vmdebug on and check the messages and memory usage.

Stefan
Title: Re: Image resize, more variations
Post by: EvanGR on October 02, 2018, 08:44:02 AM
Quote from: StefanSTS on September 26, 2018, 18:08:27 PM
Hi,

never did it that way, but I guess you could call the function for a variable instead of echo'ing it.

$myhiddenimages = $image->displayMediaThumb(... $width, $height);

The thumbs should be generated then and you can access them by name. As I said, I never tried it. Maybe keep vmdebug on and check the messages and memory usage.

Stefan

How would I get the filename (and the image URL perhaps) of the generated thumbnail, if I have several variations of them?

Thanks
Title: Re: Image resize, more variations
Post by: StefanSTS on October 03, 2018, 23:49:00 PM
Just look in the resized folder inside of the images folders for products, categories and so on.

They have an ending according to their size. So it might be: /way/to/images/virtuemart/product/resized/myimage_90x90.jpg

Title: Re: Image resize, more variations
Post by: Milbo on October 07, 2018, 12:51:14 PM
Quote from: EvanGR on October 02, 2018, 08:44:02 AM

How would I get the filename (and the image URL perhaps) of the generated thumbnail, if I have several variations of them?

Thanks

You do not really need it. Just use the function displayMediaThumb and set your desired size and it will be generated on the fly and when it exists already, it will use the already existing one, of course. So you do not need to fuddle around with the different thumbsizes. When you replace or some how change your main media, all thumbs of the media (and maybe some more) will be deleted automatically.
Title: Re: Image resize, more variations
Post by: GJC Web Design on October 07, 2018, 14:37:42 PM
for your lazy load can't u use  $imgthumb = JURI::root() . $product->images[0]->getFileUrlThumb();

the function takes sizes as well

function getFileUrlThumb($width = 0,$height = 0)

haven't tried though
Title: Re: Image resize, more variations
Post by: EvanGR on January 18, 2019, 16:00:04 PM
Hello,

It seems that displayMediaThumb does not generate new thumbnails when I call it from the template file.

e.g. for testing I am doing this..

$thumbfile = $product->images[0]->displayMediaThumb("",true,"rel='vm-additional-images'", true, true, false, 280, 280);
$thumbfile = $product->images[0]->displayMediaThumb("",true,"rel='vm-additional-images'", true, true, false, 200, 200);
$thumbfile = $product->images[0]->displayMediaThumb("",true,"rel='vm-additional-images'", true, true, false, 160, 160);



Then I look into the product/resized folder, sort files by last created, and do not see any files with the sizes given above.

Any idea?

[VM3.4.2, Dynamic Image Resizing is turned on in the settings]
Title: Re: Image resize, more variations
Post by: jenkinhill on January 18, 2019, 16:38:23 PM
You do go to tyhe product page where those files are coded to display? The files are generated only when required to display in the frontend.  Or am I mis-interpreting what you are trying to do?
Title: Re: Image resize, more variations
Post by: EvanGR on January 20, 2019, 09:57:13 AM
The code above is in the product details template file.

There is a problem with my VM setup: the full image sizes are used for product thumbnails. Even though the thumbnails are derived from the /resized/ folder, they are the same size as the original image. And the do not contain any dimensions appended to the filename (e.g. _280x280.jpg).

I am trying to troubleshoot this. Which is why I tried to force the creation of custom thumbnails with the previous code. But that does not work either.

Something broke along the way, and I don't know what.

Note: The /resized/ folder does contain a lot of properly generated thumbnails, but it may be from previous products on earlier VM installations. The current version of VM (3.4 on my test site) does not seem to generate resized thumbnails for me!
Title: Re: Image resize, more variations
Post by: PRO on January 20, 2019, 19:23:43 PM
Quote from: EvanGR on January 20, 2019, 09:57:13 AM
The code above is in the product details template file.

There is a problem with my VM setup: the full image sizes are used for product thumbnails. Even though the thumbnails are derived from the /resized/ folder, they are the same size as the original image. And the do not contain any dimensions appended to the filename (e.g. _280x280.jpg).

I am trying to troubleshoot this. Which is why I tried to force the creation of custom thumbnails with the previous code. But that does not work either.

Something broke along the way, and I don't know what.

Note: The /resized/ folder does contain a lot of properly generated thumbnails, but it may be from previous products on earlier VM installations. The current version of VM (3.4 on my test site) does not seem to generate resized thumbnails for me!
I believe thumbnail creation needs  "gd library" enabled. Is it enabled on your installation?
Title: Re: Image resize, more variations
Post by: EvanGR on January 21, 2019, 12:51:40 PM
Yes, GD is installed. I think the problem may be with the specific VM version... I am opening a new thread about this issue...