Jump to content

Image Sizer options setting quality of image


Pravin
 Share

Recommended Posts

How to set the image quality as per desired..

I tried using the above code but I get the original image size..

<!--Content with Image left-->
<?php 
    $i = 2;
    foreach($page->page_content as $each) {
    if( $i%2 == 0 ){ 
?>
   <section class="imageblock about-1">
          <div class="imageblock__content col-md-6 col-sm-4 pos-left animated fadeInLeft">
              <div class="background-image-holder">

                   <?php  
                   $option1 = array(
                                    'quality' => 60,
                                    'upscaling' => true,
                                    'cropping' => true,
                                    );

                   $pravin= $each->single_image->size(790,650,$option1); ?>
                   <img alt="image" src="<?php echo $pravin->url; ?>" />
              </div>
          </div>
                  <div class="container container-body">
                      <div class="row">
                          <div class="col-md-5 col-md-push-7 col-sm-8 col-sm-push-4 animated fadeInUp">
                              <?php echo $each->body; ?>
                          </div>
                      </div>
                      <!--end of row-->
                  </div>
                  <!--end of container-->
     
   </section>
<!--Content with Image on left-->

   <?php } else { ?>
<!--Content with Image on right-->
     <section class="imageblock about-1">
                <div class="imageblock__content col-md-6 col-sm-4 pos-right animated fadeInRight">
                    <div class="background-image-holder">
                    <?php $pravin= $each->single_image->size(790,650,$option1); ?>
                   <img alt="image" src="<?php echo $pravin->url; ?>" />
                    </div>
                </div>
                <div class="container container-body">
                    <div class="row">
                        <div class="col-md-5 col-sm-8 animated fadeInUp">
                            <?php echo $each->body; ?>
                        </div>
                    </div>
                    <!--end of row-->
                </div>
                <!--end of container-->
     </section>
  <?php } 
              ++$i;
              }         ?>
   
<!--Content with Image on right-->

 

Link to comment
Share on other sites

17 hours ago, Pravin said:

I tried using the above code but I get the original image size.

You probably have an existing image variation from before you set a custom quality setting. PW looks to see if there is an existing variation for an image before it creates one. This works well for variations of width and height, but unfortunately the quality, sharpening and upscaling settings are not recorded in the image name so you have to force a new image if you change one of these settings. Some time ago I made a wishlist post about this.

You can clear the variations for an image via the admin, or you can temporarily add 'forceNew' => true to your settings array just to create the variation, then remove it.

$option1 = array(
	'quality' => 60,
	'upscaling' => true,
	'cropping' => true,
	'forceNew' => true,
);

 

  • Like 3
Link to comment
Share on other sites

 

Spoiler

Yeah, but don't leave it in there permanently or you'll be recreating the image over and over again needlessly.

I need all the images on my site to be optimised so should i set it in the config file with 'forceNew'=> true or is there any alternate solution for the same @Robin S..

Link to comment
Share on other sites

1 minute ago, Pravin said:

I need all the images on my site to be optimised so should i set it in the config file with 'forceNew'=> true or is there any alternate solution for the same

You only need to force a new variation if there is an existing variation that was created with different quality, sharpening or upscaling settings. Once you have got rid of these existing variations you don't need to keep creating new images as that's a waste of server resources. From that point forward PW will serve your variation with the custom quality setting.

If you are sure you want all your images with quality 60 then you could set that in config.php. Or if it will vary use the options array when you get the image via the API, as you are doing.

If you want to do a one-off clearing of variations site-wide there is a module for that, but note the warning about variations used in RTE fields.

  • 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...