Skip to content

Conversation

@gabsoftware
Copy link

Applications such as ShareX will save to PNG below a certain file size (usually 2 MB) then to JPEG, so it would be useful to allow a list of mime-types instead of only one.

This pull-request enables that.

By default it allows image/png and image/jpeg.

Copy link
Owner

@migueldemoura migueldemoura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a bunch for the PR, @gabsoftware! Just left a few comments, let me know what you think.
I'll tag afterwards and add a note about the change of screenshotMimeType -> screenshotMimeTypes

exit();
}

$mimetype = isset($screenshot['tmp_name']) ? mime_content_type($screenshot['tmp_name']) : "error";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$mimetype = isset($screenshot['tmp_name']) ? mime_content_type($screenshot['tmp_name']) : "error";
$mimetype = isset($screenshot['tmp_name']) ? mime_content_type($screenshot['tmp_name']) : 'error';

// Verify size and mime type
$screenshot['size'] > $config['maxScreenshotSize'] ||
mime_content_type($screenshot['tmp_name']) !== $config['screenshotMimeType']
!in_array( $mimetype, $config['screenshotMimeTypes'], true)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
!in_array( $mimetype, $config['screenshotMimeTypes'], true)
!in_array($mimetype, $config['screenshotMimeTypes'], true)


// Generate screenshot path
do {} while (file_exists($filename = bin2hex(random_bytes(12)) . '.png'));
do {} while (file_exists($filename = bin2hex(random_bytes(12)) . '.' . ($mimetype == "image/png" ? "png" : "jpg" )));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
do {} while (file_exists($filename = bin2hex(random_bytes(12)) . '.' . ($mimetype == "image/png" ? "png" : "jpg" )));
do {} while (file_exists($filename = bin2hex(random_bytes(12)) . '.' . ($mimetype == 'image/png' ? 'png' : 'jpg' )));


// Generate screenshot path
do {} while (file_exists($filename = bin2hex(random_bytes(12)) . '.png'));
do {} while (file_exists($filename = bin2hex(random_bytes(12)) . '.' . ($mimetype == "image/png" ? "png" : "jpg" )));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone adds other mimetypes besides these 2, I guess we can't really have this assumption of using .jpg here.

'saveDirName' => '/data/',
'maxScreenshotSize' => 2 * 1048576,
'screenshotMimeType' => 'image/png'
'screenshotMimeTypes' => [ 'image/png', 'image/jpeg' ]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'screenshotMimeTypes' => [ 'image/png', 'image/jpeg' ]
'screenshotMimeTypes' => ['image/png', 'image/jpeg']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants