spacecatninja / craft-imager-x-imagekit-transformer

ImageKit transformer for Imager X
MIT License
0 stars 2 forks source link

How to apply face cropping? #2

Closed terryupton closed 1 year ago

terryupton commented 1 year ago

I am trying to achieve face cropping in imagekit. https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#face-cropping-fo-face

However, I am unsure what params I need to change inside my Transforms. Here is the current working Imgix setting:

 'BioTeaser'            => [
    'displayName' => 'Bio Teaser Image',
    'transforms'  => [
      ['width' => 400],
      ['width' => 1200],
    ],
    'defaults'    => [
      'ratio'             => 1 / 1,
      'auto'              => static function ($image) {
        if ($image instanceof \craft\elements\Asset) {
          if ($image->getFieldValue('autoEnhanceImage') === false) {
            return 'compress,format';
          }
        }
        return 'compress,format,enhance';
      },
      'transformerParams' => [
        'fit'     => 'facearea',
        'facepad' => '3.6'
      ],
    ],
  ],

When I inspect an image I see it is has these transforms: https://ik.imagekit.io/ibreoxzd1/tr:w-400,h-400,q-80,c-maintain_ratio,fo-top,zoom-0.9/Doug-Alcock-Left.jpg

I can manually update this to: https://ik.imagekit.io/ibreoxzd1/tr:w-400,h-400,q-80,c-maintain_ratio,fo-face,z-0.9/Doug-Alcock-Left.jpg to get the desired effect.

However, how am I able to change the fo-top to fo-face? I believe I can just pass the z: as a transformerParam

Thanks Terry

aelvan commented 1 year ago

The corresponding imagekit options would be something like transformerParams: { focus: 'face', z: 0.9 }. To figure out what parameters to use, you have to refer to the imagekit php library documentation, where they list the available parameters, and the corresponding URL parameter, see https://github.com/imagekit-developer/imagekit-php#list-of-supported-transformations. z actually isn't there, so apparently it's not completely updated, but..