소스 검색

Merge branch 'master' into version/4

DarthSim 1 개월 전
부모
커밋
cac693c2db
3개의 변경된 파일20개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 0
      CHANGELOG.md
  2. 15 5
      processing/processing.go
  3. 4 0
      vips/vips.go

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@
 - Fix the `Vary` header value when `IMGPROXY_AUTO_JXL` or `IMGPROXY_ENFORCE_JXL` configs are set to `true`.
 - Fix connection break when the `raw` processing option is used and the response status code does not allow a response body (such as `304 Not Modified`).
 - Fix the `If-Modified-Since` request header handling when the `raw` processing option is used.
+- Fix `X-Origin-Height` and `X-Result-Height` debug header values for animated images.
 - (pro) Fix generating thumbnails for VP9 videos with high bit depth.
 - (pro) Fix `IMGPROXY_CUSTOM_RESPONSE_HEADERS` and `IMGPROXY_RESPONSE_HEADERS_PASSTHROUGH` configs behavior when the `raw` processing option is used.
 

+ 15 - 5
processing/processing.go

@@ -88,10 +88,18 @@ func ValidatePreferredFormats() error {
 }
 
 func getImageSize(img *vips.Image) (int, int) {
-	width, height, _, _ := extractMeta(img, 0, true)
+	width, height := img.Width(), img.Height()
 
-	if pages, err := img.GetIntDefault("n-pages", 1); err != nil && pages > 0 {
-		height /= pages
+	if img.IsAnimated() {
+		// Animated images contain multiple frames, and libvips loads them stacked vertically.
+		// We want to return the size of a single frame
+		height = img.PageHeight()
+	}
+
+	// If the image is rotated by 90 or 270 degrees, we need to swap width and height
+	orientation := img.Orientation()
+	if orientation == 5 || orientation == 6 || orientation == 7 || orientation == 8 {
+		width, height = height, width
 	}
 
 	return width, height
@@ -404,12 +412,14 @@ func ProcessImage(ctx context.Context, imgdata imagedata.ImageData, po *options.
 		return nil, err
 	}
 
+	resultWidth, resultHeight := getImageSize(img)
+
 	return &Result{
 		OutData:      outData,
 		OriginWidth:  originWidth,
 		OriginHeight: originHeight,
-		ResultWidth:  img.Width(),
-		ResultHeight: img.Height(),
+		ResultWidth:  resultWidth,
+		ResultHeight: resultHeight,
 	}, nil
 }
 

+ 4 - 0
vips/vips.go

@@ -344,6 +344,10 @@ func (img *Image) Height() int {
 	return int(img.VipsImage.Ysize)
 }
 
+func (img *Image) PageHeight() int {
+	return int(C.vips_image_get_page_height(img.VipsImage))
+}
+
 func (img *Image) Pages() int {
 	p, err := img.GetIntDefault("n-pages", 1)
 	if err != nil {