1
0

process.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. package main
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "math"
  7. "runtime"
  8. "github.com/imgproxy/imgproxy/imagemeta"
  9. "golang.org/x/sync/errgroup"
  10. )
  11. const msgSmartCropNotSupported = "Smart crop is not supported by used version of libvips"
  12. var errConvertingNonSvgToSvg = newError(422, "Converting non-SVG images to SVG is not supported", "Converting non-SVG images to SVG is not supported")
  13. func imageTypeLoadSupport(imgtype imageType) bool {
  14. return imgtype == imageTypeSVG ||
  15. imgtype == imageTypeICO ||
  16. vipsTypeSupportLoad[imgtype]
  17. }
  18. func imageTypeSaveSupport(imgtype imageType) bool {
  19. return imgtype == imageTypeSVG || vipsTypeSupportSave[imgtype]
  20. }
  21. func imageTypeGoodForWeb(imgtype imageType) bool {
  22. return imgtype != imageTypeHEIC &&
  23. imgtype != imageTypeTIFF &&
  24. imgtype != imageTypeBMP
  25. }
  26. func extractMeta(img *vipsImage) (int, int, int, bool) {
  27. width := img.Width()
  28. height := img.Height()
  29. angle := vipsAngleD0
  30. flip := false
  31. orientation := img.Orientation()
  32. if orientation >= 5 && orientation <= 8 {
  33. width, height = height, width
  34. }
  35. if orientation == 3 || orientation == 4 {
  36. angle = vipsAngleD180
  37. }
  38. if orientation == 5 || orientation == 6 {
  39. angle = vipsAngleD90
  40. }
  41. if orientation == 7 || orientation == 8 {
  42. angle = vipsAngleD270
  43. }
  44. if orientation == 2 || orientation == 4 || orientation == 5 || orientation == 7 {
  45. flip = true
  46. }
  47. return width, height, angle, flip
  48. }
  49. func calcScale(width, height int, po *processingOptions, imgtype imageType) float64 {
  50. var shrink float64
  51. srcW, srcH := float64(width), float64(height)
  52. dstW, dstH := float64(po.Width), float64(po.Height)
  53. if po.Width == 0 {
  54. dstW = srcW
  55. }
  56. if po.Height == 0 {
  57. dstH = srcH
  58. }
  59. if dstW == srcW && dstH == srcH {
  60. shrink = 1
  61. } else {
  62. wshrink := srcW / dstW
  63. hshrink := srcH / dstH
  64. rt := po.ResizingType
  65. if rt == resizeAuto {
  66. srcD := width - height
  67. dstD := po.Width - po.Height
  68. if (srcD >= 0 && dstD >= 0) || (srcD < 0 && dstD < 0) {
  69. rt = resizeFill
  70. } else {
  71. rt = resizeFit
  72. }
  73. }
  74. switch {
  75. case po.Width == 0:
  76. shrink = hshrink
  77. case po.Height == 0:
  78. shrink = wshrink
  79. case rt == resizeFit:
  80. shrink = math.Max(wshrink, hshrink)
  81. default:
  82. shrink = math.Min(wshrink, hshrink)
  83. }
  84. }
  85. if !po.Enlarge && shrink < 1 && imgtype != imageTypeSVG {
  86. shrink = 1
  87. }
  88. shrink /= po.Dpr
  89. if shrink > srcW {
  90. shrink = srcW
  91. }
  92. if shrink > srcH {
  93. shrink = srcH
  94. }
  95. return 1.0 / shrink
  96. }
  97. func canScaleOnLoad(imgtype imageType, scale float64) bool {
  98. if imgtype == imageTypeSVG {
  99. return true
  100. }
  101. if conf.DisableShrinkOnLoad || scale >= 1 {
  102. return false
  103. }
  104. return imgtype == imageTypeJPEG || imgtype == imageTypeWEBP
  105. }
  106. func canFitToBytes(imgtype imageType) bool {
  107. switch imgtype {
  108. case imageTypeJPEG, imageTypeWEBP, imageTypeHEIC, imageTypeTIFF:
  109. return true
  110. default:
  111. return false
  112. }
  113. }
  114. func calcJpegShink(scale float64, imgtype imageType) int {
  115. shrink := int(1.0 / scale)
  116. switch {
  117. case shrink >= 8:
  118. return 8
  119. case shrink >= 4:
  120. return 4
  121. case shrink >= 2:
  122. return 2
  123. }
  124. return 1
  125. }
  126. func calcPosition(width, height, innerWidth, innerHeight int, gravity *gravityOptions, allowOverflow bool) (left, top int) {
  127. if gravity.Type == gravityFocusPoint {
  128. pointX := scaleInt(width, gravity.X)
  129. pointY := scaleInt(height, gravity.Y)
  130. left = pointX - innerWidth/2
  131. top = pointY - innerHeight/2
  132. } else {
  133. offX, offY := int(gravity.X), int(gravity.Y)
  134. left = (width-innerWidth+1)/2 + offX
  135. top = (height-innerHeight+1)/2 + offY
  136. if gravity.Type == gravityNorth || gravity.Type == gravityNorthEast || gravity.Type == gravityNorthWest {
  137. top = 0 + offY
  138. }
  139. if gravity.Type == gravityEast || gravity.Type == gravityNorthEast || gravity.Type == gravitySouthEast {
  140. left = width - innerWidth - offX
  141. }
  142. if gravity.Type == gravitySouth || gravity.Type == gravitySouthEast || gravity.Type == gravitySouthWest {
  143. top = height - innerHeight - offY
  144. }
  145. if gravity.Type == gravityWest || gravity.Type == gravityNorthWest || gravity.Type == gravitySouthWest {
  146. left = 0 + offX
  147. }
  148. }
  149. var minX, maxX, minY, maxY int
  150. if allowOverflow {
  151. minX, maxX = -innerWidth+1, width-1
  152. minY, maxY = -innerHeight+1, height-1
  153. } else {
  154. minX, maxX = 0, width-innerWidth
  155. minY, maxY = 0, height-innerHeight
  156. }
  157. left = maxInt(minX, minInt(left, maxX))
  158. top = maxInt(minY, minInt(top, maxY))
  159. return
  160. }
  161. func cropImage(img *vipsImage, cropWidth, cropHeight int, gravity *gravityOptions) error {
  162. if cropWidth == 0 && cropHeight == 0 {
  163. return nil
  164. }
  165. imgWidth, imgHeight := img.Width(), img.Height()
  166. cropWidth = minNonZeroInt(cropWidth, imgWidth)
  167. cropHeight = minNonZeroInt(cropHeight, imgHeight)
  168. if cropWidth >= imgWidth && cropHeight >= imgHeight {
  169. return nil
  170. }
  171. if gravity.Type == gravitySmart {
  172. if err := img.CopyMemory(); err != nil {
  173. return err
  174. }
  175. if err := img.SmartCrop(cropWidth, cropHeight); err != nil {
  176. return err
  177. }
  178. // Applying additional modifications after smart crop causes SIGSEGV on Alpine
  179. // so we have to copy memory after it
  180. return img.CopyMemory()
  181. }
  182. left, top := calcPosition(imgWidth, imgHeight, cropWidth, cropHeight, gravity, false)
  183. return img.Crop(left, top, cropWidth, cropHeight)
  184. }
  185. func prepareWatermark(wm *vipsImage, wmData *imageData, opts *watermarkOptions, imgWidth, imgHeight int) error {
  186. if err := wm.Load(wmData.Data, wmData.Type, 1, 1.0, 1); err != nil {
  187. return err
  188. }
  189. po := newProcessingOptions()
  190. po.ResizingType = resizeFit
  191. po.Dpr = 1
  192. po.Enlarge = true
  193. po.Format = wmData.Type
  194. if opts.Scale > 0 {
  195. po.Width = maxInt(scaleInt(imgWidth, opts.Scale), 1)
  196. po.Height = maxInt(scaleInt(imgHeight, opts.Scale), 1)
  197. }
  198. if err := transformImage(context.Background(), wm, wmData.Data, po, wmData.Type); err != nil {
  199. return err
  200. }
  201. if err := wm.EnsureAlpha(); err != nil {
  202. return nil
  203. }
  204. if opts.Replicate {
  205. return wm.Replicate(imgWidth, imgHeight)
  206. }
  207. left, top := calcPosition(imgWidth, imgHeight, wm.Width(), wm.Height(), &opts.Gravity, true)
  208. return wm.Embed(imgWidth, imgHeight, left, top, rgbColor{0, 0, 0})
  209. }
  210. func applyWatermark(img *vipsImage, wmData *imageData, opts *watermarkOptions, framesCount int) error {
  211. if err := img.RgbColourspace(); err != nil {
  212. return err
  213. }
  214. if err := img.CopyMemory(); err != nil {
  215. return err
  216. }
  217. wm := new(vipsImage)
  218. defer wm.Clear()
  219. width := img.Width()
  220. height := img.Height()
  221. if err := prepareWatermark(wm, wmData, opts, width, height/framesCount); err != nil {
  222. return err
  223. }
  224. if framesCount > 1 {
  225. if err := wm.Replicate(width, height); err != nil {
  226. return err
  227. }
  228. }
  229. opacity := opts.Opacity * conf.WatermarkOpacity
  230. return img.ApplyWatermark(wm, opacity)
  231. }
  232. func transformImage(ctx context.Context, img *vipsImage, data []byte, po *processingOptions, imgtype imageType) error {
  233. var (
  234. err error
  235. trimmed bool
  236. )
  237. if po.Trim.Enabled {
  238. if err = img.Trim(po.Trim.Threshold); err != nil {
  239. return err
  240. }
  241. trimmed = true
  242. }
  243. srcWidth, srcHeight, angle, flip := extractMeta(img)
  244. cropWidth, cropHeight := po.Crop.Width, po.Crop.Height
  245. cropGravity := po.Crop.Gravity
  246. if cropGravity.Type == gravityUnknown {
  247. cropGravity = po.Gravity
  248. }
  249. widthToScale := minNonZeroInt(cropWidth, srcWidth)
  250. heightToScale := minNonZeroInt(cropHeight, srcHeight)
  251. scale := calcScale(widthToScale, heightToScale, po, imgtype)
  252. cropWidth = scaleInt(cropWidth, scale)
  253. cropHeight = scaleInt(cropHeight, scale)
  254. if cropGravity.Type != gravityFocusPoint {
  255. cropGravity.X *= scale
  256. cropGravity.Y *= scale
  257. }
  258. if !trimmed && scale != 1 && data != nil && canScaleOnLoad(imgtype, scale) {
  259. if imgtype == imageTypeWEBP || imgtype == imageTypeSVG {
  260. // Do some scale-on-load
  261. if err = img.Load(data, imgtype, 1, scale, 1); err != nil {
  262. return err
  263. }
  264. } else if imgtype == imageTypeJPEG {
  265. // Do some shrink-on-load
  266. if shrink := calcJpegShink(scale, imgtype); shrink != 1 {
  267. if err = img.Load(data, imgtype, shrink, 1.0, 1); err != nil {
  268. return err
  269. }
  270. }
  271. }
  272. // Update scale after scale-on-load
  273. newWidth, newHeight, _, _ := extractMeta(img)
  274. widthToScale = scaleInt(widthToScale, float64(newWidth)/float64(srcWidth))
  275. heightToScale = scaleInt(heightToScale, float64(newHeight)/float64(srcHeight))
  276. scale = calcScale(widthToScale, heightToScale, po, imgtype)
  277. }
  278. if err = img.Rad2Float(); err != nil {
  279. return err
  280. }
  281. iccImported := false
  282. convertToLinear := conf.UseLinearColorspace && (scale != 1 || po.Dpr != 1)
  283. if convertToLinear || !img.IsSRGB() {
  284. if err = img.ImportColourProfile(true); err != nil {
  285. return err
  286. }
  287. iccImported = true
  288. }
  289. if convertToLinear {
  290. if err = img.LinearColourspace(); err != nil {
  291. return err
  292. }
  293. } else {
  294. if err = img.RgbColourspace(); err != nil {
  295. return err
  296. }
  297. }
  298. hasAlpha := img.HasAlpha()
  299. if scale != 1 {
  300. if err = img.Resize(scale, hasAlpha); err != nil {
  301. return err
  302. }
  303. }
  304. checkTimeout(ctx)
  305. if angle != vipsAngleD0 || flip {
  306. if err = img.CopyMemory(); err != nil {
  307. return err
  308. }
  309. if angle != vipsAngleD0 {
  310. if err = img.Rotate(angle); err != nil {
  311. return err
  312. }
  313. }
  314. if flip {
  315. if err = img.Flip(); err != nil {
  316. return err
  317. }
  318. }
  319. }
  320. checkTimeout(ctx)
  321. dprWidth := scaleInt(po.Width, po.Dpr)
  322. dprHeight := scaleInt(po.Height, po.Dpr)
  323. if err = cropImage(img, cropWidth, cropHeight, &cropGravity); err != nil {
  324. return err
  325. }
  326. if err = cropImage(img, dprWidth, dprHeight, &po.Gravity); err != nil {
  327. return err
  328. }
  329. checkTimeout(ctx)
  330. if !iccImported {
  331. if err = img.ImportColourProfile(false); err != nil {
  332. return err
  333. }
  334. }
  335. if err = img.RgbColourspace(); err != nil {
  336. return err
  337. }
  338. if hasAlpha && (po.Flatten || po.Format == imageTypeJPEG) {
  339. if err = img.Flatten(po.Background); err != nil {
  340. return err
  341. }
  342. }
  343. if po.Blur > 0 {
  344. if err = img.Blur(po.Blur); err != nil {
  345. return err
  346. }
  347. }
  348. if po.Sharpen > 0 {
  349. if err = img.Sharpen(po.Sharpen); err != nil {
  350. return err
  351. }
  352. }
  353. if po.Extend.Enabled && (po.Width > img.Width() || po.Height > img.Height()) {
  354. offX, offY := calcPosition(po.Width, po.Height, img.Width(), img.Height(), &po.Extend.Gravity, false)
  355. if err = img.Embed(po.Width, po.Height, offX, offY, po.Background); err != nil {
  356. return err
  357. }
  358. }
  359. checkTimeout(ctx)
  360. if po.Watermark.Enabled && watermark != nil {
  361. if err = applyWatermark(img, watermark, &po.Watermark, 1); err != nil {
  362. return err
  363. }
  364. }
  365. return img.RgbColourspace()
  366. }
  367. func transformAnimated(ctx context.Context, img *vipsImage, data []byte, po *processingOptions, imgtype imageType) error {
  368. if po.Trim.Enabled {
  369. logWarning("Trim is not supported for animated images")
  370. po.Trim.Enabled = false
  371. }
  372. imgWidth := img.Width()
  373. frameHeight, err := img.GetInt("page-height")
  374. if err != nil {
  375. return err
  376. }
  377. framesCount := minInt(img.Height()/frameHeight, conf.MaxAnimationFrames)
  378. // Double check dimensions because animated image has many frames
  379. if err = checkDimensions(imgWidth, frameHeight*framesCount); err != nil {
  380. return err
  381. }
  382. // Vips 8.8+ supports n-pages and doesn't load the whole animated image on header access
  383. if nPages, _ := img.GetInt("n-pages"); nPages > 0 {
  384. scale := 1.0
  385. // Don't do scale on load if we need to crop
  386. if po.Crop.Width == 0 && po.Crop.Height == 0 {
  387. scale = calcScale(imgWidth, frameHeight, po, imgtype)
  388. }
  389. if nPages > framesCount || canScaleOnLoad(imgtype, scale) {
  390. logNotice("Animated scale on load")
  391. // Do some scale-on-load and load only the needed frames
  392. if err = img.Load(data, imgtype, 1, scale, framesCount); err != nil {
  393. return err
  394. }
  395. }
  396. imgWidth = img.Width()
  397. frameHeight, err = img.GetInt("page-height")
  398. if err != nil {
  399. return err
  400. }
  401. }
  402. delay, err := img.GetInt("gif-delay")
  403. if err != nil {
  404. return err
  405. }
  406. loop, err := img.GetInt("gif-loop")
  407. if err != nil {
  408. return err
  409. }
  410. frames := make([]*vipsImage, framesCount)
  411. defer func() {
  412. for _, frame := range frames {
  413. frame.Clear()
  414. }
  415. }()
  416. watermarkEnabled := po.Watermark.Enabled
  417. po.Watermark.Enabled = false
  418. defer func() { po.Watermark.Enabled = watermarkEnabled }()
  419. var errg errgroup.Group
  420. for i := 0; i < framesCount; i++ {
  421. ind := i
  422. errg.Go(func() error {
  423. frame := new(vipsImage)
  424. if err = img.Extract(frame, 0, ind*frameHeight, imgWidth, frameHeight); err != nil {
  425. return err
  426. }
  427. if err = transformImage(ctx, frame, nil, po, imgtype); err != nil {
  428. return err
  429. }
  430. frames[ind] = frame
  431. return nil
  432. })
  433. }
  434. if err = errg.Wait(); err != nil {
  435. return err
  436. }
  437. checkTimeout(ctx)
  438. if err = img.Arrayjoin(frames); err != nil {
  439. return err
  440. }
  441. if watermarkEnabled && watermark != nil {
  442. if err = applyWatermark(img, watermark, &po.Watermark, framesCount); err != nil {
  443. return err
  444. }
  445. }
  446. img.SetInt("page-height", frames[0].Height())
  447. img.SetInt("gif-delay", delay)
  448. img.SetInt("gif-loop", loop)
  449. img.SetInt("n-pages", framesCount)
  450. return nil
  451. }
  452. func getIcoData(imgdata *imageData) (*imageData, error) {
  453. icoMeta, err := imagemeta.DecodeIcoMeta(bytes.NewReader(imgdata.Data))
  454. if err != nil {
  455. return nil, err
  456. }
  457. offset := icoMeta.BestImageOffset()
  458. size := icoMeta.BestImageSize()
  459. data := imgdata.Data[offset : offset+size]
  460. var format string
  461. meta, err := imagemeta.DecodeMeta(bytes.NewReader(data))
  462. if err != nil {
  463. // Looks like it's BMP with an incomplete header
  464. if d, err := imagemeta.FixBmpHeader(data); err == nil {
  465. format = "bmp"
  466. data = d
  467. } else {
  468. return nil, err
  469. }
  470. } else {
  471. format = meta.Format()
  472. }
  473. if imgtype, ok := imageTypes[format]; ok && vipsTypeSupportLoad[imgtype] {
  474. return &imageData{
  475. Data: data,
  476. Type: imgtype,
  477. }, nil
  478. }
  479. return nil, fmt.Errorf("Can't load %s from ICO", meta.Format())
  480. }
  481. func saveImageToFitBytes(po *processingOptions, img *vipsImage) ([]byte, context.CancelFunc, error) {
  482. var diff float64
  483. quality := po.Quality
  484. img.CopyMemory()
  485. for {
  486. result, cancel, err := img.Save(po.Format, quality, conf.StripMetadata)
  487. if len(result) <= po.MaxBytes || quality <= 10 || err != nil {
  488. return result, cancel, err
  489. }
  490. cancel()
  491. delta := float64(len(result)) / float64(po.MaxBytes)
  492. switch {
  493. case delta > 3:
  494. diff = 0.25
  495. case delta > 1.5:
  496. diff = 0.5
  497. default:
  498. diff = 0.75
  499. }
  500. quality = int(float64(quality) * diff)
  501. }
  502. }
  503. func processImage(ctx context.Context) ([]byte, context.CancelFunc, error) {
  504. runtime.LockOSThread()
  505. defer runtime.UnlockOSThread()
  506. if newRelicEnabled {
  507. newRelicCancel := startNewRelicSegment(ctx, "Processing image")
  508. defer newRelicCancel()
  509. }
  510. if prometheusEnabled {
  511. defer startPrometheusDuration(prometheusProcessingDuration)()
  512. }
  513. defer vipsCleanup()
  514. po := getProcessingOptions(ctx)
  515. imgdata := getImageData(ctx)
  516. if po.Format == imageTypeUnknown {
  517. switch {
  518. case po.PreferWebP && imageTypeSaveSupport(imageTypeWEBP):
  519. po.Format = imageTypeWEBP
  520. case imageTypeSaveSupport(imgdata.Type) && imageTypeGoodForWeb(imgdata.Type):
  521. po.Format = imgdata.Type
  522. default:
  523. po.Format = imageTypeJPEG
  524. }
  525. } else if po.EnforceWebP && imageTypeSaveSupport(imageTypeWEBP) {
  526. po.Format = imageTypeWEBP
  527. }
  528. if po.Format == imageTypeSVG {
  529. if imgdata.Type != imageTypeSVG {
  530. return []byte{}, func() {}, errConvertingNonSvgToSvg
  531. }
  532. return imgdata.Data, func() {}, nil
  533. }
  534. if imgdata.Type == imageTypeSVG && !vipsTypeSupportLoad[imageTypeSVG] {
  535. return []byte{}, func() {}, errSourceImageTypeNotSupported
  536. }
  537. if imgdata.Type == imageTypeICO {
  538. icodata, err := getIcoData(imgdata)
  539. if err != nil {
  540. return nil, func() {}, err
  541. }
  542. imgdata = icodata
  543. }
  544. if !vipsSupportSmartcrop {
  545. if po.Gravity.Type == gravitySmart {
  546. logWarning(msgSmartCropNotSupported)
  547. po.Gravity.Type = gravityCenter
  548. }
  549. if po.Crop.Gravity.Type == gravitySmart {
  550. logWarning(msgSmartCropNotSupported)
  551. po.Crop.Gravity.Type = gravityCenter
  552. }
  553. }
  554. if po.ResizingType == resizeCrop {
  555. logWarning("`crop` resizing type is deprecated and will be removed in future versions. Use `crop` processing option instead")
  556. po.Crop.Width, po.Crop.Height = po.Width, po.Height
  557. po.ResizingType = resizeFit
  558. po.Width, po.Height = 0, 0
  559. }
  560. animationSupport := conf.MaxAnimationFrames > 1 && vipsSupportAnimation(imgdata.Type) && vipsSupportAnimation(po.Format)
  561. pages := 1
  562. if animationSupport {
  563. pages = -1
  564. }
  565. img := new(vipsImage)
  566. defer img.Clear()
  567. if err := img.Load(imgdata.Data, imgdata.Type, 1, 1.0, pages); err != nil {
  568. return nil, func() {}, err
  569. }
  570. if animationSupport && img.IsAnimated() {
  571. if err := transformAnimated(ctx, img, imgdata.Data, po, imgdata.Type); err != nil {
  572. return nil, func() {}, err
  573. }
  574. } else {
  575. if err := transformImage(ctx, img, imgdata.Data, po, imgdata.Type); err != nil {
  576. return nil, func() {}, err
  577. }
  578. }
  579. checkTimeout(ctx)
  580. if po.Format == imageTypeGIF {
  581. if err := img.CastUchar(); err != nil {
  582. return nil, func() {}, err
  583. }
  584. checkTimeout(ctx)
  585. }
  586. if po.MaxBytes > 0 && canFitToBytes(po.Format) {
  587. return saveImageToFitBytes(po, img)
  588. }
  589. return img.Save(po.Format, po.Quality, conf.StripMetadata)
  590. }