Skip to content

Commit

Permalink
fix: handle regression
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi committed Nov 19, 2023
1 parent e3220b4 commit 3e94140
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions impl/image_resizer/client/image_resizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,24 @@ img, err := vips.NewImageFromBuffer(image)
// Get original size of image
originalWidth := float64(img.Width())
originalHeight := float64(img.Height())

// Calculate scale factors for width and height
scaleWidth := float64(width) / originalWidth
scaleWidth := float64(width) / originalWidth
scaleHeight := float64(height) / originalHeight

// Use the smaller scale factor to ensure the entire image fits within the specified dimensions
scaleFactor := math.Min(scaleWidth, scaleHeight)
scaleFactor := math.Min(scaleWidth, scaleHeight)

if originalWidth == originalHeight {
if err = img.Resize(scaleFactor, vips.KernelNearest); err != nil {
return
}
} else {
if height < width {
width = height
}

if height > int(originalHeight) {
height = int(originalHeight)
}

// Crop the image to the specified dimensions while maintaining the aspect ratio
if err = img.SmartCrop(width, height, vips.InterestingCentre); err != nil {
return
Expand Down

0 comments on commit 3e94140

Please sign in to comment.