I have a somewhat unique thumbnail need for a certain site. I need to watermark images with custom text (per image, not globally across the site). Is there a way to hook into the Craft image transform generation logic and insert/run my own logic?

I've experimented with craft()->on('content.onSaveContent', function(Event $event) { and it seems to work okay. It will run when you save/upload the asset. The downside is that it generates the thumbnail on save, instead of on demand (using Javascript) as the native Craft transform feature does.

So, is there a different event I can hook into? Or, is there a better way to adjust the transform generation logic.


Currently it’s not possible to hook into Craft’s own thumbnail/transform generation logic. Your best bet would be to write a plugin that independently adds the watermark.

You could give the plugin a Variable class that accepts the AssetFileModel object, grabs the image, stamps it with the watermark and saves it somewhere else, returning the URL to that watermarked image, or something like that.

  • Interesting, however with this I won't be able to use any of the on-demand asset transforms? That's not a deal breaker in this case but wonder if Craft will ever support custom transforms. – Mark Huot Jul 17 '14 at 13:46
  • Yeah it would need to be separate. We are planning on giving plugins a role in transforms, but can’t give you an ETA. – Brandon Kelly Jul 17 '14 at 14:09
  • Thanks Brandon! No worries, the separate approach will work fine in this specific instance. – Mark Huot Jul 18 '14 at 14:25

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.