Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Image actions applied to theme images?

Started by Muut Archive 11 years ago · 4 replies · 376 views
11 years ago

Is it possible to apply image actions (ie: grayscale, resize, crop) to images from the theme directory? Something like this:

TWIG
<img src="{{ url('theme://images', true) }}/my_image.png?grayscale">

Thanks in advance for your help.

11 years ago

An image usually needs to be associated with page for it to be treated as page media and therefore, have the media functions work correctly.

That said, you can put my_image.png under user/pages/images/my_image.png and reference it in markdown as:

![](/images/test2.jpg?grayscale

In a twig file:

{{ "![](/images/test2.jpg?grayscale)"|markdown }}

or

{{ grav.pages.dispatch('/images').media['test2.jpg'].grayscale }}

11 years ago

Thanks for the info. Bummer on not being able to apply actions to theme images.

11 years ago

The reason for this is because these images associated with pages are sort of pre-processed during the page processing, and wrapped up in a Grav object that can do many things.

When you reference an image directly via an HTML tag, you are actually just asking the web server to send you the image. Grav is not running or processing.

It could be possible for a plugin to basically intercept a special request and do that work, but it would incur some performance penalty because it would mean running a Grav process for each image request you make.

BTW, this doesn't happen with page images because these are processed and cached as actual image files, then referenced as such from the content. So there's no performance penalty.

11 years ago

I understand. No worries. We'll probably end up running them through that specific page so we can apply actions (as suggested). Thanks so much!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1346 9 years ago
Archive · by Muut Archive, 9 years ago
2 933 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2945 9 years ago
Archive · by Muut Archive, 9 years ago
3 1117 9 years ago