Git Product home page Git Product logo

Comments (7)

CostaC avatar CostaC commented on August 24, 2024

Here's my code:

$imagine = new \Imagine\Gd\Imagine();
$image = $imagine->open($dir_uploads2.DS.$fn_shot);


//figure out size of cropped image
$image_box = $image->getSize();
$width = $image_box->getWidth()-28;     //border x 2 = 28px
$height = $image_box->getHeight();
$cropped_size = new Imagine\Image\Box($width, $height);



//add black border
$border_width = 50;
$new_box = $image->getSize()->increase($border_width*2);
$color = new Imagine\Image\Color('000');    //black
$image2 = $imagine->create($new_box,  $color);
$border_startpoint = new Imagine\Image\Point($border_width,$border_width);
$image2->paste($image, $border_startpoint);

//output new image          
$image2->save($dir_uploads2.DS.$fn_shot);

from imagine.

jmikola avatar jmikola commented on August 24, 2024

What kind of canvas dimensions are you working with? Imagine works with true color image resources, and those are prone to taking up quite a bit of memory (at least 3 bytes per pixel). I've run into similar issues of high memory consumption while resizing uploaded images. Despite limiting uploads to a few MB, a highly compressed JPG could expand considerably in memory when opened as an image resource.

from imagine.

avalanche123 avatar avalanche123 commented on August 24, 2024

Alternatively I suggest using Imagick/Gmagick drivers as those won't keep image in memory

from imagine.

CostaC avatar CostaC commented on August 24, 2024

My images are 2000 x 1500 JPGs.

And being a shared server I can't install Imagick/Gmagick :(

from imagine.

avalanche123 avatar avalanche123 commented on August 24, 2024

You run out of memory processing just one image or are you using it for mass processing?

from imagine.

CostaC avatar CostaC commented on August 24, 2024

Multiple images but one at a time in a loop, so the $image and $image2 vars are being replaced every iteration.

I was able to workaround this issue by adding an unset($image) before the ->save call, I guess the ->save creates another copy of the image and 3 copies of the image was too much for 64Mb:

unset($image)
$image2->save($dir_uploads2.DS.$fn_shot);

Thanks for the help guys.

from imagine.

utterly-calm avatar utterly-calm commented on August 24, 2024

unset($image) isn't working for me, I have to use ini_set('memory_limit', '1024M'); to make it work. But that has a limitation in itself, if inside loop there are more than 50 images each 3-7MB in size, it may break after allocating '1024M' but if I use ini_set('memory_limit', '-1'); that is unlimited memory. It will never break but this is not the correct way of solving this issue because this unlimited memory allocation can cause other damage to the server as well. So what would be the best way to resolve it.

from imagine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.