-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1495 from anyproto/go-3889-adjust-file-extension-…
- Loading branch information
Showing
8 changed files
with
133 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package mill | ||
|
||
import ( | ||
"fmt" | ||
"image" | ||
"image/jpeg" | ||
"io" | ||
"strconv" | ||
|
||
"github.com/disintegration/imaging" | ||
"github.com/oov/psd" | ||
) | ||
|
||
func (m *ImageResize) resizePSD(imgConfig *image.Config, r io.ReadSeeker) (res *Result, err error) { | ||
img, _, err := psd.Decode(r, &psd.DecodeOptions{SkipLayerImage: true}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var height int | ||
width, err := strconv.Atoi(m.Opts.Width) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid width: " + m.Opts.Width) | ||
} | ||
|
||
resized := imaging.Resize(img.Picker, width, 0, imaging.Lanczos) | ||
width, height = resized.Rect.Max.X, resized.Rect.Max.Y | ||
|
||
quality, err := strconv.Atoi(m.Opts.Quality) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid quality: " + m.Opts.Quality) | ||
} | ||
|
||
buf := pool.Get() | ||
defer func() { | ||
_ = buf.Close() | ||
}() | ||
|
||
// encode to jpeg encoding to increase compatibility on mobile devices | ||
if err = jpeg.Encode(buf, resized, &jpeg.Options{Quality: quality}); err != nil { | ||
return nil, err | ||
} | ||
readSeekCloser, err := buf.GetReadSeekCloser() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &Result{ | ||
File: readSeekCloser, | ||
Meta: map[string]interface{}{ | ||
"width": width, | ||
"height": height, | ||
}, | ||
}, nil | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.