干预:两次调整图像大小?

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?

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');

I'm posting this to help others who might come across a similar issue. While we can implement @user6421733's answer... There's a better way of handling different sizes of images.

Consider using Intervention's imagecache optional package. You could implement it simply too. http://image.intervention.io/use/url

It can allow you to use urls such as this http://yourhost.com/{route-name}/original/{file-name} and with little or less effort: