diff --git a/Makefile b/Makefile index cae9a87b..6506adae 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,12 @@ windows-build: # Creates Windows executable linux-build: # Creates Linux executable @GOOS=linux GOARCH=amd64 go build -ldflags=${LDFLAGS} -o build/comics-downloader ./cmd/downloader +raspbian-build-arm: # Creates Raspbian executable + @GOOS=linux GOARCH=arm go build -ldflags=${LDFLAGS} -o build/comics-downloader-raspbian-arm ./cmd/downloader + +raspbian-build-arm64: # Creates Raspbian executable + @GOOS=linux GOARCH=arm64 go build -ldflags=${LDFLAGS} -o build/comics-downloader-raspbian-arm64 ./cmd/downloader + osx-gui-build: # Creates OSX Gui executable @GOOS=darwin GOARCH=amd64 go build -ldflags=${LDFLAGS} -o build/comics-downloader-gui-osx ./cmd/gui diff --git a/cmd/app/downloader.go b/cmd/app/downloader.go index 873230b8..bf6f34aa 100644 --- a/cmd/app/downloader.go +++ b/cmd/app/downloader.go @@ -37,11 +37,6 @@ func Run(link, format, country string, all, bindLogsToChannel bool) { sendToChannel(bindLogsToChannel, msg) } - // TODO: This doesn't seem necessary - if !strings.HasSuffix(link, ",") { - link = link + "," - } - for _, u := range strings.Split(link, ",") { if u != "" { // check if the link is supported diff --git a/pkg/core/core.go b/pkg/core/core.go index 06434a7e..08e4dfea 100644 --- a/pkg/core/core.go +++ b/pkg/core/core.go @@ -76,12 +76,12 @@ func (comic *Comic) retrieveImageFromResponse(response *http.Response) (io.Reade } imgData := new(bytes.Buffer) - if err := util.ConvertTo8BitPNG(img, imgData); err != nil { + if err := util.ConvertToJPG(img, imgData); err != nil { return content, tp, err } content = imgData - tp = "png" + tp = "jpg" default: content = response.Body tp = util.ImageType(response.Header["Content-Type"][0]) @@ -200,23 +200,22 @@ func (comic *Comic) makePDF() error { for _, link := range comic.Links { if link != "" { rsp, err := http.Get(link) - if err == nil { - defer rsp.Body.Close() - // add a new PDF page - pdf.AddPage() - content, tp, err := comic.retrieveImageFromResponse(rsp) - if err != nil { - return err - } - // The image is directly added to the pdf without being saved to the disk - imageOptions := gofpdf.ImageOptions{ImageType: tp, ReadDpi: false, AllowNegativePosition: true} - pdf.RegisterImageOptionsReader(link, imageOptions, content) - // set the image position on the pdf page - pdf.Image(link, 0, 0, 210, 0, false, tp, 0, "") - // increase the progressbar - } else { + if err != nil { + return err + } + + defer rsp.Body.Close() + // add a new PDF page + pdf.AddPage() + content, tp, err := comic.retrieveImageFromResponse(rsp) + if err != nil { return err } + imageOptions := gofpdf.ImageOptions{ImageType: tp, ReadDpi: true, AllowNegativePosition: false} + pdf.RegisterImageOptionsReader(link, imageOptions, content) + // set the image position on the pdf page + pdf.Image(link, 0, 0, 210, 297, false, tp, 0, "") + // increase the progressbar } if barErr := bar.Add(1); barErr != nil { log.Error(barErr) diff --git a/pkg/util/util.go b/pkg/util/util.go index b3e02359..7dcca52b 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -4,8 +4,7 @@ import ( "bytes" "fmt" "image" - "image/color" - "image/png" + "image/jpeg" "net/url" "os" "path/filepath" @@ -55,19 +54,9 @@ func IsValueInSlice(valueToCheck string, values []string) bool { return false } -// ConvertTo8BitPNG converts an image of any type to a PNG with 8-bit color depth -func ConvertTo8BitPNG(img image.Image, imgData *bytes.Buffer) error { - b := img.Bounds() - imgSet := image.NewRGBA(b) - // Converts each pixel to a 32-bit RGBA pixel - for y := 0; y < b.Max.Y; y++ { - for x := 0; x < b.Max.X; x++ { - newPixel := color.RGBAModel.Convert(img.At(x, y)) - imgSet.Set(x, y, newPixel) - } - } - - err := png.Encode(imgData, imgSet) +// ConvertToJPG converts an image to jpeg +func ConvertToJPG(img image.Image, imgData *bytes.Buffer) error { + err := jpeg.Encode(imgData, img, nil) if err != nil { return err } diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index f32ef9d4..e1eff4e8 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -53,7 +53,7 @@ func TestConvertImage(t *testing.T) { img, _ := png.Decode(resp.Body) imgData := new(bytes.Buffer) - err = ConvertTo8BitPNG(img, imgData) + err = ConvertToJPG(img, imgData) assert.Nil(t, err) }