nystudio107 / craft-imageoptimize

Automatically create & optimize responsive image transforms, using either native Craft transforms or a service like Imgix, with zero template changes.
https://nystudio107.com/plugins/imageoptimize
Other
235 stars 36 forks source link

Environment is ignored in the settings file #234

Closed terryupton closed 3 years ago

terryupton commented 3 years ago

Describe the bug

It appears that the Environment is ignored in the settings file. I believe this is a recent bug as this was working ok a few weeks ago.

To reproduce

Steps to reproduce the behaviour:

  1. In my settings file I am setting different paths to the imageProcessors for a local environment. I do this like so;
 // Local (development) environment
  'local'                            => [
    // Preset image processors
    'imageProcessors' => [
      // jpeg optimizers
      'jpegoptim' => [
        'commandPath'           => '/usr/local/bin/jpegoptim',
        'commandOptions'        => '-s',
        'commandOutputFileFlag' => '',
      ],
      'mozjpeg'   => [
        'commandPath'           => '/usr/local/bin/mozjpeg',
        'commandOptions'        => '-optimize -copy none',
        'commandOutputFileFlag' => '-outfile',
      ],
      'jpegtran'  => [
        'commandPath'           => '/usr/local/bin/jpegtran',
        'commandOptions'        => '-optimize -copy none',
        'commandOutputFileFlag' => '',
      ],
      // png optimizers
      'optipng'   => [
        'commandPath'           => '/usr/local/bin/optipng',
        'commandOptions'        => '-o3 -strip all',
        'commandOutputFileFlag' => '',
      ],
      'pngcrush'  => [
        'commandPath'           => '/usr/local/bin/pngcrush',
        'commandOptions'        => '-brute -ow',
        'commandOutputFileFlag' => '',
      ],
      'pngquant'  => [
        'commandPath'           => '/usr/local/bin/pngquant',
        'commandOptions'        => '--strip--skip -if-larger',
        'commandOutputFileFlag' => '',
      ],
      // svg optimizers
      'svgo'      => [
        'commandPath'           => '/usr/local/bin/svgo',
        'commandOptions'        => '',
        'commandOutputFileFlag' => '',
      ],
      // gif optimizers
      'gifsicle'  => [
        'commandPath'           => '/usr/local/bin/gifsicle',
        'commandOptions'        => '-O3 -k 256',
        'commandOutputFileFlag' => '',
      ],
    ],

    'imageVariantCreators' => [
      // webp variant creator
      'cwebp' => [
        'commandPath'           => '/usr/local/bin/cwebp',
        'commandOptions'        => '',
        'commandOutputFileFlag' => '-o',
        'commandQualityFlag'    => '-q',
        'imageVariantExtension' => 'webp',
      ],
    ],

I have the following in my .env file ENVIRONMENT=local

However, this is ignored and the settings are not updated. I can verify this by checking the imageOptimize settings to see if the Active Image Processors are installed.

Screenshot 2020-10-26 at 12 30 37

If I remove the 'local' => [ setting then this works as expected and the Image Processors paths are updated.

Screenshot 2020-10-26 at 12 31 03

I can verify that I the environment is local by testing for this in a template.

  {% set env = getenv('ENVIRONMENT') %}
  {{ env }}
Screenshot 2020-10-26 at 12 32 37

Expected behaviour

I expect in the local environment for the Image Processors to use different paths, based on the ENVIRONMENT setting in the .env file.

Versions

terryupton commented 3 years ago

This was a bug in my code. So closing this issue.