Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intervention: Resize image twice?

I want to resize an image twice using Intervention.

I have this currently:

$img = Image::make($image_url);

$img_path = public_path() . '/images/';

$img->fit(500, 250);
$img->save($img_path . '/img_250.jpg');

$img = Image::make($image_url);

$img->fit(100, 100);
$img->save($img_path . '/img_100.jpg');

As you can see, I first want to resize the original image to 500x250, and then I want to again resize the original image (not the 500x250 image) to 100x100.

Is there a way to do this without calling Image::make() twice?


1 Answers

Here's the answer:

http://image.intervention.io/api/reset

// create an image
$img = Image::make('public/foo.jpg');

// backup status
$img->backup();

// perform some modifications
$img->resize(320, 240);
$img->invert();
$img->save('public/small.jpg');

// reset image (return to backup state)
$img->reset();

// perform other modifications
$img->resize(640, 480);
$img->invert();
$img->save('public/large.jpg');