Jump to content

Get Image "quality" value from $image instance?


Gazley
 Share

Recommended Posts

Hi there,

I'm using ImageSizerEngineIMagic and it has an overridable, default image quality value.

In my application code, you can override the module's value based on a user Page field value. However, if there is no "custom" value in the page field, I'd like to be able to access the ImageSizerEngineIMagic module's default value.

There is likely a very easy way to do this. If anyone could point me to it, I'd be very grateful! :)

Many thanks. 

Link to comment
Share on other sites

Hi Gazley,

I'm not sure if I fully get what you are after, but I try to answer. :)

You can access an Imagesizer instance like this:

$ImageSizer = new ImageSizer();

// or, maybe better, with an image-filename
$filename = $page->images->first()->filename;
$ImageSizer = new ImageSizer($filename);

Now you can query everything you want:

$quality = $ImageSizer->quality; // returns the calculated value from: engine-default-setting => wire/config.php => site/config.php

EDIT:

Or do you mean the new modules configurable default settings of the ImagesizerEngines?

If yes, you can use the $modules method getModuleConfigData()

$configdata = wire('modules')->getModuleConfigData('ImageSizerEngineIMagic');
$defaultQuality = $configdata['quality'];
Edited by horst
  • Like 3
Link to comment
Share on other sites

Hi @horst - many thanks for your reply. It's a really great answer and I appreciate you taking the time to provide this information.

I guess I thought some metadata, like "quality", could be accessed directly from an Image instance but as you have shown, it's easy enough to new-up an ImageSizer object.

Thank you! :)

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...