happywire Posted March 15, 2019 Share Posted March 15, 2019 [solution] ======================================================== I installed the ImageSizerEngineIMagick module and am using @Soma 's hook to create image variations in the admin panel when uploading a new image. 1. How can I limit the ImageSizerEngineIMagick module to not create image variations that are above the original file's dimensions? For example I have this image.https://www.jpl.nasa.gov/spaceimages/details.php?id=PIA13128 Full resolution. https://photojournal.jpl.nasa.gov/jpeg/PIA13128.jpg Using Soma's hook and adding the image variation sizes I want to be created like this.. <?php // https://gist.github.com/somatonic/5685631 // not all the hook is inserted here, this is just to show the image size variations public function sizeImage($event) { $inputfield = $event->object; if ($inputfield->name != 'images') return; $defaultOptions = array( 'upscaling' => false, 'cropping' => false, 'quality' => 100 ); $image = $event->argumentsByName("pagefile"); $image->size(9000, 0, $defaultOptions); $image->size(7680, 0, $defaultOptions); $image->size(3200, 0, $defaultOptions); $image->size(2560, 0, $defaultOptions); $image->size(1920, 0, $defaultOptions); $image->size(1280, 0, $defaultOptions); $image->size(800, 0, $defaultOptions); $image->size(768, 0, $defaultOptions); $image->size(240, 0, $defaultOptions); $image->size(180, 0, $defaultOptions); } ..I get the following image size variations. This means that regardless of image dimensions there are variations created that are above the original file dimension. How can I tell the module or include what logic in the hook that I do not want to create image variations that are above the dimensions of the original image? 2. The original is max 2MB big and has a max width of 4801px. Having the quality set to 100 in the module I get images that have a bigger file size than the original at a lower dimension. An image variation of 1920px width is created with 2.9MB. An image variation of 2560px width is created with 4.4MB. An image variation of 3200px width is created with 6.0MB. Setting the quality to 90 following image variations are created. Does that mean I cannot put the quality setting of the module to 100 as otherwise image variations that have a higher file size than the original are being created at lower dimensions of the original? Does ImageMagick work like this with the quality being 100? Link to comment Share on other sites More sharing options...
Autofahrn Posted March 15, 2019 Share Posted March 15, 2019 3 hours ago, happywire said: How can I limit the ImageSizerEngineIMagick module to not create image variations that are above the original file's dimensions? What about: if($image->width > 9000) $image->size(9000, 0, $defaultOptions); I'd anyway prefer something generic like (You'll probably want to account for landscape and portrait as well): $imgWidth = $image->width; while($imgWidth > 400) // Larger than minimum? { $imgWidth /= 2; // half size (or whatever factor) $image->size($imgWidth, 0, $defaultOptions); } Not sure about the ImageMagick quality setting, but "max" quality of a JPEG normally relates to its (I'll name it) "cluster" size. The higher the quality setting, the smaller the cluster is. This has nothing to do with "keep quality from original", which may be encoded with a lower quality setting, which seems to be the case in your example. 2 1 Link to comment Share on other sites More sharing options...
happywire Posted March 23, 2019 Author Share Posted March 23, 2019 It really is that easy! Thank you! On 3/15/2019 at 6:00 PM, Autofahrn said: Not sure about the ImageMagick quality setting, but "max" quality of a JPEG normally relates to its (I'll name it) "cluster" size. The higher the quality setting, the smaller the cluster is. This has nothing to do with "keep quality from original", which may be encoded with a lower quality setting, which seems to be the case in your example. Great to know this, now that part makes a lot more sense, invaluable information. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now