4

I have an image transform that is designed for images inserted into posts, and I'd like to make sure this is always applied to any image in a post. The problem I'm having is that for images inserted via Rich Text Fields, selecting a transform is optional, and the wrong transform may be selected.

Ideally I'd like to set a default transform so I can tell content editors that they can insert images directly into posts and don't need to do anything with the "Select image transform" option... is there any way of doing this, though? Any help or advice would be much appreciated!

  • 3
    Hey Nick, if you haven't already I'd recommend looking into a matrix field for adding the page content. You can set up a block type for text, and a block type for image, and would make for a much easier experience for any content editors. – Jamie Wade Dec 3 '14 at 7:39
  • Thanks Jamie - excellent suggestion: as it happens I already am doing pretty much exactly that! :) However, the text block type is rich text, and although we do have separate Image blocks, the client wants to also be able to insert images inline in text blocks too. Tbh, with the extra degree of control over the image that you get when you insert them this way it does make sense that they want this. The image blocks aren't a problem - they seamlessly use the desired image transform - but I'm trying to also catch those images that get inserted via redactor in rich text fields. – Nick F Dec 3 '14 at 10:52
  • Hmmm, that's a strange request! To be honest I can't see any advantage to inserting images inline with Redactor; as you say you get so much more control with inserting them through the image block. I'd recommend you put your foot down with the client and make them use matrix, but that's just me ;) – Jamie Wade Dec 3 '14 at 11:33
  • 1
    Ah, no sorry - I meant you get more control when you insert them via redactor. Personally, I really like the "asset in an image block" approach, but redactor does allow easy resizing, inserting smaller images inline in text blocks, etc, so I can understand why they want to be able to do this. – Nick F Dec 3 '14 at 11:36
  • Sure no worries. Obviously I'm not telling you how to build your site here, I'm just giving you an alternative. Matrix is built for exactly this kind of work, pretty much anything is possible within it. You can handle the image re-sizing with a simple dropdown field, whereby the transform for the image changes depending on which option is selected, and you can position the image using the Craft positioning field: buildwithcraft.com/docs/position-select-fields etc. Something to think about :) – Jamie Wade Dec 3 '14 at 11:41
5

I don't think it's possible natively, yet (as of 2.3). However, the ImageSmith plugin addresses this need by providing a 'bulk transform' Twig filter which detects images in HTML, applies a specified transform, and rewrites the HTML to reference the transformed images.

| improve this answer | |
1

I just published a plugin called Retcon HTML – this includes a Twig filter for applying an image transform (named or inline) to all <img> tags in arbitrary HTML content (unfortunately only for local assets, for now).

See this Wiki page for specific instructions on how to apply image transforms with Retcon.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.