mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
perf(storage): skip no-op imagick transforms and add transform value spans
- Only call crop() when dimensions > 0 or gravity differs from center - Only call setOpacity() when opacity !== 1.0 (was always called due to !empty(1.0)) - Only call setBorder() when borderWidth > 0 - Only call setBorderRadius() when borderRadius > 0 - Only call setRotation() when rotation !== 0 - Add Span::add() with actual values inside each transform condition - Leave output() unconditional (format conversion always applies)
This commit is contained in:
@@ -241,28 +241,43 @@ class Get extends Action
|
||||
throw new Exception(Exception::STORAGE_FILE_TYPE_UNSUPPORTED, $e->getMessage());
|
||||
}
|
||||
|
||||
$image->crop((int) $width, (int) $height, $gravity);
|
||||
if ($width > 0 || $height > 0 || $gravity !== Image::GRAVITY_CENTER) {
|
||||
Span::add('storage.transform.crop.width', $width);
|
||||
Span::add('storage.transform.crop.height', $height);
|
||||
Span::add('storage.transform.crop.gravity', $gravity);
|
||||
$image->crop($width, $height, $gravity);
|
||||
}
|
||||
|
||||
if (!empty($opacity)) {
|
||||
if ($opacity !== 1.0) {
|
||||
Span::add('storage.transform.opacity', $opacity);
|
||||
$image->setOpacity($opacity);
|
||||
}
|
||||
|
||||
if (!empty($background)) {
|
||||
Span::add('storage.transform.background', $background);
|
||||
$image->setBackground('#' . $background);
|
||||
}
|
||||
|
||||
if (!empty($borderWidth)) {
|
||||
if ($borderWidth > 0) {
|
||||
Span::add('storage.transform.border.width', $borderWidth);
|
||||
Span::add('storage.transform.border.color', $borderColor);
|
||||
$image->setBorder($borderWidth, '#' . $borderColor);
|
||||
}
|
||||
|
||||
if (!empty($borderRadius)) {
|
||||
if ($borderRadius > 0) {
|
||||
Span::add('storage.transform.borderRadius', $borderRadius);
|
||||
$image->setBorderRadius($borderRadius);
|
||||
}
|
||||
|
||||
if (!empty($rotation)) {
|
||||
if ($rotation !== 0) {
|
||||
Span::add('storage.transform.rotation', $rotation);
|
||||
$image->setRotation(($rotation + 360) % 360);
|
||||
}
|
||||
|
||||
if ($quality !== -1) {
|
||||
Span::add('storage.transform.quality', $quality);
|
||||
}
|
||||
|
||||
$data = $image->output($output, $quality);
|
||||
|
||||
$renderingTime = \microtime(true) - $startTime - $downloadTime - $decryptionTime - $decompressionTime;
|
||||
|
||||
Reference in New Issue
Block a user