Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/Service/ImageResizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,28 @@
class ImageResizer {
public const RESIZE_MAX_X = 256;
public const RESIZE_MAX_Y = 256;
public const MAX_INPUT_BYTES = 5 * 1024 * 1024;
public const MAX_INPUT_PIXELS = 4096 * 4096;

/**
* @param string $socialData
* @return null|string
*/
public function resizeImage(string $socialData) {
$image = new Image();
if ($socialData === '' || strlen($socialData) > self::MAX_INPUT_BYTES) {
return null;
}

$size = @getimagesizefromstring($socialData);
if ($size === false || !isset($size[0], $size[1])) {
return null;
}

if ($size[0] <= 0 || $size[1] <= 0 || ($size[0] * $size[1]) > self::MAX_INPUT_PIXELS) {
return null;
}

$image = new Image();
$image->loadFromData($socialData);

if ($image->valid()) {
Expand Down