Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ioutil.TempFile: file extension as suffix #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions magick.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,18 @@ func NewFromBlob(blob []byte, extension string) (im *MagickImage, err error) {
success = C.GetBlobSupport(info)
if success != C.MagickTrue {
// No blob support, lets try reading from a file
file, err := ioutil.TempFile("", "image."+extension)
file, err := ioutil.TempFile("", "image")
if _, err = file.Write(blob); err != nil {
return nil, &MagickError{"fatal", "", "image format " + extension + " does not support blobs and could not write temp file"}
}
file.Close()
return NewFromFile(file.Name())

// ioutil.TempFile adds a random int as suffix, which confuses ImageMagick. Add the extension to the end of filename instead.
newFilename := file.Name() + "." + extension
os.Rename(file.Name(), newFilename)
defer os.Remove(newFilename)

return NewFromFile(newFilename)
}
length := (C.size_t)(len(blob))
if length == 0 {
Expand Down