Jump to content
Usman

Image Variations takes more time as compared to local

Recommended Posts

Currently my system is using nginx server on production recently upgraded from processwire 2.5 to processwire 2.7.2
We are making multiple dimension sizes of images. On our system it is taking very less time locally on apache server.
Tested this on another system it work fine there, even tested on nginx locally.
 
Issue arises when we deploy it to server , the performance goes slow and hence it is taking more than normal time.

if an image locally take 2 seconds for variations on server same image take almost 50s to 1 min(excluding uploading time).

Here is a code for creating image variations.

<?php
class ImageCreateThumbs extends WireData implements Module {

    public static function getModuleInfo() {
        return array(
            'title' => 'ImageCreateThumbs',
            'version' => 100,
            'summary' => 'This module allows creation of multiple sized images.',
            'href' => '',
            'singular' => true,
            'autoload' => true
            );
    }

    public function init() {
        $this->addHookAfter('InputfieldFile::fileAdded', $this, 'sizeImage');
    }

    public function sizeImage($event) {
        $inputfield = $event->object;
        if($inputfield->name != 'images' && $inputfield->name != 'image' && $inputfield->name != 'asset_image') return; // we assume images field

        $image = $event->argumentsByName("pagefile");
        $image->size(350,0);
        $image->size(480,0);
        $image->size(560,0);
        $image->size(680,0);
        $image->size(760,0);
        $image->size(840,0);
        $image->size(960,0);
        $image->size(1200,0);
        $image->size(1400,0);
        $image->size(1500,0);
        $image->size(1900,0);
        $image->size(2000,0);
        $image->size(2400,0);
    }
}
Edited by LostKobrakai
Added codeblock

Share this post


Link to post
Share on other sites

Are you sure the server does actually have an equivalent amount of horsepower available compared to your computer? Image resizing is highly cpu intensive and therefore dependent on the servers hardware. 

  • Like 1

Share this post


Link to post
Share on other sites

If you are able to do, I would suggest to create a simple testsite with latest PW 3.0.16 and enable the IMagick ImageSizerExtension.

Would be interesting to compare the time on the exact same server.

  • Like 1

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ttttim
      I was recently experimenting with optimizing my images to get better load results. The code below is an example of what i've been using. It works nicely but the main problem is if i load a page for the first time after having added a few images my server will overload and return a 503 error. I have to refresh the page a few times for the server to resize all the images. Not a big problem while developing but not something I want on my live website. 
      <picture> <source media='(max-width: 320px)' srcset='{$image->width(320)->url} 1x, {$image->width(640)->url} 2x'> <source media='(max-width: 375px)' srcset='{$image->width(375)->url} 1x, {$image->width(750)->url} 2x'> <source media='(max-width: 767px)' srcset='{$image->width(750)->url} 1x, {$image->width(1500)->url} 2x'> <source media='(max-width: 1023px)' srcset='{$image->width(300)->url} 1x, {$image->width(600)->url} 2x'> <source media='(max-width: 1319px)' srcset='{$image->width(450)->url} 1x, {$image->width(900)->url} 2x'> <source media='(min-width: 1320px)' srcset='{$image->width(510)->url} 1x, {$image->width(1020)->url} 2x'> <img src='{$image->width(1056)->url}' alt='$image->description'> </picture>"; Is there a way to create these different sizes without overloading my server? 
      Ideally i'd like to expand the above code with webp support and a service like tinyPNG to reduce image size even further, but that would stretch the first load time even further. 
    • By Pravin
      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-->  
    • By lenoir
      Hi,
      I've recently upgraded a website to the latest version (2.7.2) and the image fields are not running properly. Seems like the ImageSizer isn't working anymore. There's a thread in the forums about that particular problem but it's a dead-end.
      Here's the error i got:
      ImageSizer::resize(0, 100) failed for [...]/site/assets/cache/WireTempDir/.PagefilesManager1984/1/numbers_layout.0x100.jpg Can anyone help me with this? Thanks.
    • By owzim
      I'd like to resize some images on demand, that are not page images, so they are not attached to a page.
      How to use the ImageSizer class? I could browse through the code but perhaps someone who used this, could provide some lines of example code.
      I basically want to pass the image path and cropping options.
      Are the cropped images saved somewhere if they are not page images, or will the cropping be executed every time?
      Thanks!
    • By robinc
      I have an issue where I want to have an image resized, but have both a cropped and non-cropped version available (of the same size!)
      The code to do this is simple:
      $imagefull = $image->size(320,320,array( 'cropping' => false); $imagecropped = $image->size(320,320,array( 'cropping' => true); However, this only creates ONE variant of the image:
      eg. imagename.320x320.jpg
      So the same image is shown twice in the output page, instead of the two options
      Can anyone suggest a clean way of doing this? (ie. not duplicating every base image)
      Is there a way of creating named Image Variations? And do these names go into the filename to guarantee uniqueness?
      eg. $image->addVariation($name,$size,$options) or similar
      Thanks
×
×
  • Create New...