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

Resize all images in a page

Started by Muut Archive 10 years ago · 12 replies · 1139 views
10 years ago

Hi everyone :)

I need to resize by default all the images of a page template.
The images are within the markdown content :P

Thks !!!

10 years ago

If they are inside the markdown content the easiest thing probably is to resize them using CSS

10 years ago

It works, but I have images that are too heavy (> 2MB) and that the resize would help much ;)

10 years ago

Hi Hugo !!!!

In this case I have the following considerations:

  1. The content resides in markdown originally, specify here which limits their use in other templates you need another size.
  2. The page template defines that size resizes.
  3. In the page template the content is html, so could not be used resizing via url parameter (only available markdown or twig)

thks !!, I appreciate your help :)

10 years ago

How many images are on the pages? At that size, Grav's caching is unlikely to handle the process of resizing very well. Not quite sure what you're saying about the considerations, are you trying to achieve responsive images? If so, you probably need to generate these outside of Grav and apply a srcset-attribute.

10 years ago

Hi OleVik !!

  1. They are a few images per page, up to 10.
  2. About considerations, mainly because the editor is up pictures very large resolutions, and when viewing the page load very slow.
  3. It is a good idea what the responsive images, but how to generate the images out of grav, even loading the content from the administrator panel in markdown?

Thks !!!

10 years ago

Not sure about loading the content in Admin, but if you let the original images stay with the post then I imagine it will work seamlessly in editing. This Gist has some examples of building responsive images, which work well with the ImgSrcset-plugin, but does require that you use NodeJS locally to generate them.

10 years ago

Hi OleVik !!

One more consideration :P

  1. Grav is used for a site that is continuously updated by different users who manage images and content through the page editor.

With this scenario, it would run gulp whenever there is a change in the content?

10 years ago

No, the Gulpfile-chain has to be run on demand - and you'd need a host with NodeJS installed to run it in on a server. It is a crude solution to a problem that Grav, really PHP, is not particularly good at handling: Manipulating many large images and handling resources well.

Most of PHPs image-manipulation libraries, both integrated and auxiliary, handle such processes rather poorly as PHP is a high-level language but not aimed at filesystem-manipulation like Python, C, or Node. Thus they tend to fail at emptying memory caches and releasing processes when handling large files (no sane PHP developer will tell you to use it for large file handling) - even images which are relatively small in raw format.

So its use-case is limited to a workflow where an editor, not a writer, finalizes content before deploying it to a live or staging environment. I am looking into apt ways of doing this in PHP rather than Node, but shared hosting just isn't set up to handle these scenarios with raw images - which writers tend to use (or at least are requested to use for these purposes).

10 years ago

Hi OleVik !!

Just in case it has better hardware and overlook the performance incoveniente php, how it could implement handling images of grav to resolve this situation?

10 years ago

A plugin could implement a different PHP library than Gregwar, and there have been some suggestions for alternatives. For Node the same would apply, but it would mean a plugin would have to interface with Node to execute the Gulpfile.

Of the two, Node is more convenient and probably would be less of a drain on the servers memory and processing power for its tight integration with the filesystem. But PHP would still be preferred for its ability to work more universally as server hosts rarely run both PHP and Node, and Grav runs on the former.

10 years ago

Hi OleVik !!!

I'll consider your advice, I'm very short of time to change the library so far only editor I will establish rules to upload images not so heavy.

Thks a lot !!! :D

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1361 9 years ago
Archive · by Muut Archive, 9 years ago
2 939 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2958 9 years ago
Archive · by Muut Archive, 9 years ago
3 1123 9 years ago