Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Extending Recton Services #52

Open
martin-coded opened this issue Apr 23, 2023 · 8 comments
Open

Question: Extending Recton Services #52

martin-coded opened this issue Apr 23, 2023 · 8 comments
Labels

Comments

@martin-coded
Copy link

Is there an easy way to add a custom transform service method to your RetconService class?

@mmikkel
Copy link
Owner

mmikkel commented Apr 23, 2023

@Martin-1988 I don't think so. Can you elaborate on specifically what you're looking to achieve?

@martin-coded
Copy link
Author

I am trying to figure out, how we can use Retcon with the imageOptimize plugin when someone added images to a redactor field.

The usage of the imageOptimize plugin looks something like this.

twig

{% set thumbnail = entry.articleImage.one().optimizedArticleThumbnail %}
<img src="{{ thumbnail.src() }}" srcset="{{ thumbnail.srcsetWebP() }}" sizes="(max-width: 991px) 95vw, (max-width: 1350px) 45vw, 756px">

and as a result, we have this.

html

<img 
	src="/assets/images/thumbnails/_760x427_crop_center-center_60_line/923311/my-super-image.jpg" 
	srcset="/assets/images/thumbnails/_760x427_crop_center-center_60_line/923311/my-super-image.jpg.webp 760w, /assets/images/thumbnails/_1520x855_crop_center-center_45_line/923311/my-super-image.jpg.webp 1520w, /assets/images/thumbnails/_2280x1282_crop_center-center_30_line/923311/my-super-image.jpg.webp 2280w, /assets/images/thumbnails/_450x253_crop_center-center_60_line/923311/my-super-image.jpg.webp 450w, /assets/images/thumbnails/_900x506_crop_center-center_45_line/923311/my-super-image.jpg.webp 900w, /assets/images/thumbnails/_1350x759_crop_center-center_30_line/923311/my-super-image.jpg.webp 1350w, /assets/images/thumbnails/_350x196_crop_center-center_30_line/923311/my-super-image.jpg.webp 350w, /assets/images/thumbnails/_700x393_crop_center-center_22_line/923311/my-super-image.jpg.webp 700w, /assets/images/thumbnails/_1050x590_crop_center-center_15_line/923311/my-super-image.jpg.webp 1050w"
	sizes="(max-width: 991px) 95vw, (max-width: 1350px) 45vw, 756px">

Or would it be easier to achieve this, with the imagerX plugin?

@mmikkel
Copy link
Owner

mmikkel commented Apr 23, 2023

The biggest obstacle to use either ImageOptimize or Imager's pre-transform features with Retcon is the fact that Retcon won't actually use the original assets when generating transforms (it will actually parse any reference tags in the image nodes' src attribute before attempting to transform them). Hence, Retcon operates on strings (i.e. image URLs) and not asset models, and so I think that will make it impossible to reconcile Retcon's transform or srcset methods with features in either IO or Imager that relies on actual asset models.

If you need this level of control over how image transforms are generated, my recommendation would be to use separate fields or block types for the images (i.e. not have them inside the WYSIWYG content), if at all possible. Retcon's transform features are fairly bare-bones on purpose.

@mmikkel mmikkel closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2023
@mmikkel mmikkel reopened this Aug 4, 2023
@mmikkel
Copy link
Owner

mmikkel commented Aug 4, 2023

I've got some changes planned for transforms in Retcon 3.0 which could be helpful for cases like this.

@daniellelecomte
Copy link

daniellelecomte commented Mar 22, 2024

Hi @mmikkel - do you have an ETA on v3? Bumping up against this on a site with loads of legacy entries using retcon w/ imager and lambda.

@mmikkel
Copy link
Owner

mmikkel commented Mar 22, 2024

@daniellelecomte Retcon 3.0.0-beta.1 has actually been tagged, but it’s a Craft 5 compatibility release and there are no changes.

I might or might not still do a bigger Retcon refactor at some point (perhaps as a 4.0), but it’s not something I’m working on ATM.

@daniellelecomte
Copy link

Appreciate the quick reply! Any suggestions on a work-around?

@mmikkel
Copy link
Owner

mmikkel commented Mar 22, 2024

Appreciate the quick reply! Any suggestions on a work-around?

No, not really. As I mentioned above, ImageOptimize and Imager pre-transforms aren’t compatible with Retcon’s transform filters (which have essentially stayed the same since Craft 2 and pre-dates both of those). I’m not seeing a way to reconcile these features without making some fundamental changes to Retcon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants