kekekiw123's avatar

trying to set image quality with intervention when using Storage(s3)

I am trying to set the image quality when I use image intervention

Reading the docs it says that quality can be set when using save():

$img->save('public/bar.png', 100);

But I never use the save() function since I dont want to store any images on my server, I want to store them on amazon s3 using the store function.

This is what I use:

public function uploadLargeAndMainImages($file,$id)
    {
      $s3 = Storage::disk('s3');
      $extension = $file->guessExtension();
      $filename = uniqid() . '.' . $extension;

      //Create and resize images
      $image = Image::make($file)->resize(null, 600, function ($constraint) {
          $constraint->aspectRatio();
      });
      $image->encode($extension);

      $imageLarge = Image::make($file)->resize(null, 800, function ($constraint) {
          $constraint->aspectRatio();
      });
      $imageLarge->encode($extension);

      // upload image to S3
      $s3->put("images/{$id}/medium/" . $filename, (string) $image, 'public');
      $s3->put("images/{$id}/large/" . $filename, (string) $imageLarge, 'public');
    }

This will never set the image quality, so must I first save the images on my server then upload them to amazon s3 if I wish to set the quality?

0 likes
4 replies
spekkionu's avatar

PNG is lossless so quality is a redundant parameter anyway.

For pngs intervention uses the second parameter for compression level.

$imagine->open('/path/to/image.jpg')->save('/path/to/image.png', array('png_compression_level' => 9));
tykus's avatar

For pngs intervention uses the second parameter for compression level.

Is this true for Intervention; I have never seen this in the docs?

spekkionu's avatar

Is this true for Intervention; I have never seen this in the docs?

Silly me, I pulled that from imagine/imagine rather than intervention/image. My bookmarks for those packages are right next to each other and I must have clicked the wrong one.

Please or to participate in this conversation.