2

I am trying to upload an image and scale it to maximum 200px width or 200px height depends which is bigger, using Imagine.

I read this link: Imagine where it says:

If one of thumbnail dimensions is set to null, another one is calculated automatically based on aspect ratio of original image.

I Tried this code to change the width:

Image::thumbnail($target, 200, null)->save($target_to);

got an error: Exception Imagine\Exception\InvalidArgumentException with message Length side cannot be 0 or negative.

I am also trying to upload png files with transparent background. Looking at the same link it says:

If thumbnail mode is ImageInterface::THUMBNAIL_INSET, the original image is scaled down so it is fully contained within the thumbnail dimensions. The rest is filled with background that could be configured via yii\imagine\Image::$thumbnailBackgroundColor and yii\imagine\Image::$thumbnailBackgroundAlpha.

Looking at the links they give, it says it will fill:

$thumbnailBackgroundAlpha public static property (available since version 2.0.4) Background alpha (transparency) to use when creating thumbnails in ImageInterface::THUMBNAIL_INSET mode with both width and height specified. Default is solid. public static string $thumbnailBackgroundAlpha = 100 $thumbnailBackgroundColor public static property (available since version 2.0.4) Background color to use when creating thumbnails in ImageInterface::THUMBNAIL_INSET mode with both width and height specified. Default is white. public static string $thumbnailBackgroundColor = 'FFF'

I have 2 questions:

  1. Will this keep the transparent background? public static string $thumbnailBackgroundAlpha = 100 $thumbnailBackgroundColor public static property (available since version 2.0.4)

  2. I don't want to give width and height, only one dimension so the image will be resized accordingly. How do I do that?

Sigal Zahavi
  • 1,045
  • 2
  • 21
  • 42

1 Answers1

0

Image thumbnail As in latest releases, passing null as an argument is making the respective null argument value as zero and hence exception is thrown. You can solve it using as shown in the image. As you can see in the code, I have passed only width parameter i.e 400 and calculated height using the same and passed to the thumbnail method.

Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84