getgrav

Open full view…

Can you implement a "random" feature ?

Christophe Mondiès
Mon, 27 Oct 2014 23:50:37 GMT

{% set showcase_image = page.media.images|first %} is working. Can you implement {% set showcase_image = page.media.images|random %} to get a random picture in the folder ? Thanks !

dvoo
Mon, 03 Nov 2014 21:45:23 GMT

Is there a way to adjust the quality of an image? My problem is that I get big artefacts on my showcase image, caused by the automatic compression. Thanks

rhukster
Mon, 03 Nov 2014 22:26:41 GMT

Actually in current version there is not a good way to do this. However, i've just commited a method github (`quality()`) that let's you do this for example: ``` {% set blog_image = page.media.images|first.grayscale().contrast(30).quality(90).brightnes s(-100).colorize(-35,81,122) %} ``` You can add this method yourself to your current version. It will be part of the next release.

rhukster
Tue, 04 Nov 2014 04:13:27 GMT

Ooops, forgot the link: https://github.com/getgrav/grav/commit/aecdbaaa27fc3ba230a36e0afa56a8196cee4fae

dvoo
Tue, 04 Nov 2014 18:02:03 GMT

Thank you rhukster, Works like a charm :)

thoomyy
Wed, 06 Jul 2016 08:21:39 GMT

Hey, is there any possibility to set a folder, where all images are in?

flaviocopes
Wed, 06 Jul 2016 10:38:13 GMT

Is this related to the topic? You want a random image from that folder?

thoomyy
Wed, 06 Jul 2016 11:33:07 GMT

yes from a defined folder

flaviocopes
Wed, 06 Jul 2016 11:42:25 GMT

You can have a user/pages/images folder, and randomize an image from that folder with `page.find('/images').media.images|randomize|first`

tastas
Sun, 31 Jul 2016 19:28:07 GMT

>You can have a user/pages/images folder, and randomize an image from that folder with page.find('/images').media.images|randomize|first Thanks for this, it works very well for the blog template. But I cannot make it work with showcase item of a modular page. It chooses one random image at first when you clear the site cache but then keeps using the same image even though randomization works on the blog page. Should I change something in the syntax to make it work with showcase items?

tastas
Sun, 31 Jul 2016 19:45:39 GMT

I have also tried this syntax but it does the same thing; picks a random image just at first load. --- {% set showcase_image = random(page.find('/images').media.images) %} ---

wsanter
Sun, 31 Jul 2016 21:23:28 GMT

You could try to disable the caching in the page Advanced tab

tastas
Sun, 31 Jul 2016 21:27:47 GMT

The same syntax works on the blog template without disabling the caching though? I'd like to keep caching enabled.

wsanter
Sun, 31 Jul 2016 21:34:36 GMT

I never tried the random function in a modular page, so i can't help

tastas
Tue, 02 Aug 2016 05:51:35 GMT

I guess this is not possible. Oh well, I think I'll need to upload images twice. One set for the showcase using the code in the first reply and one set for the blog page using the code I quoted before.

tastas
Tue, 02 Aug 2016 05:59:04 GMT

Hmm... Nope, I could not make this work for modular page showcase template either... --- {% set showcase_image = page.media.images|randomize %} --- So what I get is, random image thing works with regular pages but not modular pages.

grodo
Wed, 07 Dec 2016 17:43:21 GMT

Working for me in modular pages with the --- {% set showcase_image = page.find('/images').media.images|randomize|first %} --- method. The problem I'm having is only jpegs are displayed but gifs are ignored, I guess because calling --- images --- ignores the gif 'animated' filetype. I wonder if there's a method to call for any media, not just images.

flaviocopes
Wed, 07 Dec 2016 18:40:08 GMT

Use `.all` instead of `.images`

netogulga
Sat, 24 Jun 2017 08:06:40 GMT

I have a question... to hide some of the images in the media.images how could we do it? ext. 00.jpg 01.jpg ??

rhukster
Sun, 25 Jun 2017 15:14:52 GMT

Maybe loop over the array first, and remove specific images, then after that call `|randomize` filter,

netogulga
Mon, 26 Jun 2017 05:19:51 GMT

thanxx

next