Add a config option like sanitizeCpImageUploads
but for plugin/module/CLI requests
#15430
-
We have a site that initiates image uploads via calls to a custom module. These are images coming from the client's custom-built DAM, and these are high-resolution images of artwork, that have been specifically saved with the Adobe RGB color profile. When these images are uploaded and saved, the image is sanitized; this sanitization process ends up converting the color profile to sRGB, which sometimes results in significant color shifts from the original image. Because of the nature of the site (a contemporary art gallery), this is an important issue for the client (not withstanding everyone understanding that colors on the web are never going to be consistent across monitors & devices!). If we upload these images via the CP, we can disable sanitization by setting sanitizeCpImageUploads to The relevant code is: https://github.com/craftcms/cms/blob/4.x/src/elements/Asset.php#L2901-L2911
So the request is, to give us some way to skip sanitization for these non-CP, non-frontend requests. Note that this site is built on Craft 4.x, so if there is a solution, we'd love to see it available for 4.x. Also: FWIW we are using GD instead of ImageMagick, because we have found that ImageMagick sometimes is unable to determine an image's width & height when initially uploaded (this is our experience across multiple client sites, we've never been able to get to the bottom of why, but assume it's a memory issue). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Just discussed this internally. It would be a little confusing to have two separate config settings that determine sanitization, so instead I added a new You can set it to use craft\base\Element;
use craft\base\Event;
use craft\elements\Asset;
use craft\events\ModelEvent;
Event::on(Asset::class, Element::EVENT_BEFORE_SAVE, function(ModelEvent $event) {
/** @var Asset $asset */
$asset = $event->sender;
$asset->sanitizeOnUpload = false;
}); This is for 4.11 and 5.3+, so you will need to switch over to the "craftcms/cms": "4.11.x-dev as 4.11.0-alpha", |
Beta Was this translation helpful? Give feedback.
Just discussed this internally. It would be a little confusing to have two separate config settings that determine sanitization, so instead I added a new
$sanitizeOnUpload
property tocraft\elements\Asset
. If it’s set, it will take precedence oversanitizeCpImageUploads
+ the request type.You can set it to
false
by registering anEVENT_BEFORE_SAVE
event handler from a module:This is for 4.11 and 5.3+, so you…