4

I see how to use Image Transforms when the image tag is its own field but don't see a way to handle images within Rich Text fields or force a size on upload.

I need to have the image dimensions match the size the client sized the image to in the Rich Text field. Is there a way to do this?

3

If you create an image transform in the control panel, the client will be able to choose that transform when selecting an image (in the bottom right corner). But there's no way to get Craft to transform the image based on the size the clients manually set the image to be in the rich text field.

1

If you want to customize the image transforms from your templates, you’re going to be better off using a Matrix field instead. You can give the field two block types, “Text” and “Image”, with Rich Text and Assets sub-fields, respectively. Then from your templates, you will have full control over the images’ dimensions when they are output.

  • We've done that with our site but then the problem we encounter is that all the legacy content that we've imported isnt possible to be divided appropriately into the matrix field structure. Would it be possible with a Twig Extension to gather all images and then generate a custom transform with the output? – Sean O'Grady Oct 17 '14 at 13:57
  • 1
    You would be able to parse out the images, but by that point the actual asset model will be lost, and searching for assets based on their URL isn’t very easy to do. – Brandon Kelly Oct 17 '14 at 17:24
  • @Sean a hacky workaround would be to use the getRawContent() method on your redactor field and then apply your custom Twig filter. Have a look at the built-in filter to parse reference tags (Docs: parseRefs, source code: public function parseRefs($str)) that you could modify upon. – carlcs Nov 18 '14 at 13:05
  • 1
    Hi Brandon, sorry to drag up an old post. Just wondering if there's any official way now of specifying image transforms for image assets in a Rich Text field, to be applied at template render time. There will be situations where implementing the aforementioned solution just aren't possible. Thanks in advance. – Brendan Underwood Feb 24 '15 at 4:02

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.