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:
Will this keep the transparent background? public static string $thumbnailBackgroundAlpha = 100 $thumbnailBackgroundColor public static property (available since version 2.0.4)
I don't want to give width and height, only one dimension so the image will be resized accordingly. How do I do that?