Commit 11d0db5d authored by brent's avatar brent

modify watermark

parent d8c648e8
...@@ -381,23 +381,38 @@ func downloadImage(url string) (image.Image, string, error) { ...@@ -381,23 +381,38 @@ func downloadImage(url string) (image.Image, string, error) {
logs.Debug("filetype.Match error = ", err) logs.Debug("filetype.Match error = ", err)
return nil, "", err return nil, "", err
} }
timestamp := time.Now().Unix()
timestampStr := strconv.FormatInt(timestamp, 10)
file, err := os.Create("./" + timestampStr + "_download_replicate_img." + kind.Extension)
defer file.Close()
defer os.Remove(file.Name())
if err != nil {
fmt.Println("Error creating file:", err)
return nil, "", err
}
_, err = file.Write(body)
if err != nil {
fmt.Println("Error writing to file:", err)
return nil, "", err
}
img, format, err := image.Decode(resp.Body) img, format, err := image.Decode(resp.Body)
if err != nil { if err != nil {
mime := kind.MIME.Value mime := kind.MIME.Value
if mime == "image/webp" { if mime == "image/webp" {
format = "webp" format = "webp"
file, err := downloadFile(url)
img, err = decodeWebP(file) img, err = decodeWebP(file)
defer file.Close() if err != nil {
defer os.Remove(file.Name()) return nil, "", err
//img, err = webp.Decode(resp.Body) }
} else if mime == "image/png" {
img, err = png.Decode(file)
if err != nil { if err != nil {
return nil, "", err return nil, "", err
} }
} else { } else {
return nil, "", err return nil, "", err
} }
} }
return img, format, nil return img, format, nil
} }
...@@ -1270,7 +1285,7 @@ func doGetReplicate(url string, task *models.Task, taskResponse *models.TaskResp ...@@ -1270,7 +1285,7 @@ func doGetReplicate(url string, task *models.Task, taskResponse *models.TaskResp
if len(output) > 0 { if len(output) > 0 {
isImage := checkFileIsImage(output) isImage := checkFileIsImage(output)
if isImage == 1 { if isImage == 1 {
task.Output = transferImagesToS3(output, task) task.Output = transferFileToS3(output, task, true)
} else if isImage == 2 { } else if isImage == 2 {
task.Output = transferFileToS3(output, task, true) task.Output = transferFileToS3(output, task, true)
} else { } else {
......
{"/Users/brent/Documents/wubanWork/aon_app_server/controllers":1724388875286732771} {"/Users/brent/Documents/wubanWork/aon_app_server/controllers":1724394908152124565}
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment