Fixed handling of JPEG
This commit is contained in:
parent
acd9ac6cdb
commit
3630bfb0cb
2 changed files with 3 additions and 2 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"image"
|
"image"
|
||||||
|
_ "image/jpeg"
|
||||||
"image/png"
|
"image/png"
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
|
@ -16,12 +17,12 @@ func ResizeImg(file multipart.File, width int, height int) ([]byte, error) {
|
||||||
fileContent, err := io.ReadAll(file)
|
fileContent, err := io.ReadAll(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("Error reading image file")
|
return nil, errors.New("Error reading image file")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode image
|
// Decode image
|
||||||
img, _, err := image.Decode(bytes.NewReader(fileContent))
|
img, _, err := image.Decode(bytes.NewReader(fileContent))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
println(err.Error())
|
||||||
return nil, errors.New("Error decoding image")
|
return nil, errors.New("Error decoding image")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ Atridad Lahiji // Tools // Resizer
|
||||||
<h2 class="text-2xl font-extrabold tracking-tight text-white sm:text-[2rem]">Image Resizer</h2>
|
<h2 class="text-2xl font-extrabold tracking-tight text-white sm:text-[2rem]">Image Resizer</h2>
|
||||||
<form action="/api/resize" method="post" enctype="multipart/form-data" class="flex-col flex gap-4">
|
<form action="/api/resize" method="post" enctype="multipart/form-data" class="flex-col flex gap-4">
|
||||||
Select image to resize:
|
Select image to resize:
|
||||||
<input type="file" name="image" accept="image/*"
|
<input type="file" name="image" accept=".png,.jpg,.jpeg"
|
||||||
class="file-input file-input-bordered file-input-secondary w-full max-w-xs" required />
|
class="file-input file-input-bordered file-input-secondary w-full max-w-xs" required />
|
||||||
<br>
|
<br>
|
||||||
New width (px):
|
New width (px):
|
||||||
|
|
Loading…
Add table
Reference in a new issue