vector_guard_scale.go 603 B

123456789101112131415161718192021222324
  1. package processing
  2. import (
  3. "math"
  4. )
  5. // vectorGuardScale checks if the image is a vector format and downscales it
  6. // to the maximum allowed resolution if necessary
  7. func vectorGuardScale(c *Context) error {
  8. if c.ImgData == nil || !c.ImgData.Format().IsVector() {
  9. return nil
  10. }
  11. if resolution := c.Img.Width() * c.Img.Height(); resolution > c.PO.SecurityOptions.MaxSrcResolution {
  12. scale := math.Sqrt(float64(c.PO.SecurityOptions.MaxSrcResolution) / float64(resolution))
  13. c.VectorBaseScale = scale
  14. if err := c.Img.Load(c.ImgData, 1, scale, 1); err != nil {
  15. return err
  16. }
  17. }
  18. return nil
  19. }