Skip to content

Commit

Permalink
Add ffmpeg (#62)
Browse files Browse the repository at this point in the history
* build(go): bump the go version to 1.23

* build(gomod): add ffmpeg as dep

* feat(images): refactor the convertToImage function to use ffmpeg under the hood

* feat(images): call the converteToImage  function using ffmpeg supporting avif now

* feat(files): add avif to the supported formats list

* docs(readme): add avif format to the tables of supported formats on the readme file

* ci(actions): update linux deps

* docs(images): add doc comments to the convertToImage functions
  • Loading branch information
danvergara authored Aug 25, 2024
1 parent 2bd7e32 commit a9852aa
Show file tree
Hide file tree
Showing 16 changed files with 305 additions and 173 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
- name: Install libreoffice
go-version: "1.23"
- name: Install linux dependencies
run: |
sudo apt-get update
sudo apt-get update && sudo apt-get upgrade
sudo apt-get -y install libreoffice
- name: Install dependencies
- name: Setup ffmpeg
uses: FedericoCarboni/setup-ffmpeg@v3
id: setup-ffmpeg
with:
ffmpeg-version: 6.1.0
github-token: ${{ github.server_url == 'https://github.com' && github.token || '' }}
- name: Install Go dependencies
run: go get .
- name: Test
run: go test -v ./...
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the application from source
FROM golang:1.21 AS builder
FROM golang:1.23 AS builder

ARG TARGETOS
ARG TARGETARCH
Expand All @@ -25,7 +25,7 @@ FROM debian:trixie-slim AS release
WORKDIR /

RUN apt-get update \
&& apt-get install -y --no-install-recommends default-jre libreoffice libreoffice-java-common \
&& apt-get install -y --no-install-recommends default-jre libreoffice libreoffice-java-common ffmpeg \
&& apt-get autoremove -y \
&& apt-get purge -y --auto-remove \
&& rm -rf /var/lib/apt/lists/*
Expand Down
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ A modal will pop up with a preview of the converted image.

### Images X Images

| | PNG | JPEG | GIF | WEBP | TIFF | BMP |
|-------|-------|--------|-------|--------|--------|-------|
| PNG | ||||||
| JPEG || |||||
| GIF ||| ||||
| WEBP |||| |||
| TIFF ||||| ||
| BMP |||||| |
| | PNG | JPEG | GIF | WEBP | TIFF | BMP | AVIF |
|-------|-------|--------|-------|--------|--------|-------|--------|
| PNG | |||||||
| JPEG || ||||||
| GIF ||| |||||
| WEBP |||| ||||
| TIFF ||||| |||
| BMP |||||| ||
| AVIF ||||||| |

### Images X Documents

Expand All @@ -91,12 +92,13 @@ A modal will pop up with a preview of the converted image.
| WEBP ||
| TIFF ||
| BMP ||
| AVIF | |

## Documents X Images

| | PNG | JPEG | GIF | WEBP | TIFF | BMP |
| --- | --- | ---- | --- | ---- | ---- | --- |
| PDF |||||||
| | PNG | JPEG | GIF | WEBP | TIFF | BMP | AVIF |
| --- | --- | ---- | --- | ---- | ---- | --- | ---- |
| PDF ||||||| |

## Documents X Documents

Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/danvergara/morphos

go 1.21.3
go 1.23.0

require (
github.com/chai2010/webp v1.1.1
Expand All @@ -10,15 +10,18 @@ require (
github.com/signintech/gopdf v0.20.0
github.com/stretchr/testify v1.8.4
github.com/tealeg/xlsx/v3 v3.3.6
github.com/u2takey/ffmpeg-go v0.5.0
golang.org/x/image v0.14.0
golang.org/x/text v0.14.0
)

require (
github.com/aws/aws-sdk-go v1.38.20 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/frankban/quicktest v1.14.6 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/peterbourgon/diskv/v3 v3.0.1 // indirect
Expand All @@ -28,6 +31,7 @@ require (
github.com/rogpeppe/fastuuid v1.2.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/shabbyrobe/xmlwriter v0.0.0-20200208144257-9fca06d00ffa // indirect
github.com/u2takey/go-utils v0.3.1 // indirect
golang.org/x/net v0.18.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
50 changes: 50 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
github.com/aws/aws-sdk-go v1.38.20 h1:QbzNx/tdfATbdKfubBpkt84OM6oBkxQZRw6+bW2GyeA=
github.com/aws/aws-sdk-go v1.38.20/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/chai2010/webp v1.1.1 h1:jTRmEccAJ4MGrhFOrPMpNGIJ/eybIgwKpcACsrTEapk=
github.com/chai2010/webp v1.1.1/go.mod h1:0XVwvZWdjjdxpUEIf7b9g9VkHFnInUSYujwqTLEuldU=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gen2brain/go-fitz v1.23.7 h1:HPhzEVzmOINvCKqQgB/DwMzYh4ArIgy3tMwq1eJTcbg=
github.com/gen2brain/go-fitz v1.23.7/go.mod h1:HU04vc+RisUh/kvEd2pB0LAxmK1oyXdN4ftyshUr9rQ=
github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk=
github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/panjf2000/ants/v2 v2.4.2/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OIhFxRNFr4A=
github.com/peterbourgon/diskv/v3 v3.0.1 h1:x06SQA46+PKIUftmEujdwSEpIx8kR+M9eLYsUxeYveU=
github.com/peterbourgon/diskv/v3 v3.0.1/go.mod h1:kJ5Ny7vLdARGU3WUuy6uzO6T0nb/2gWcT1JiBvRmb5o=
github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 h1:zyWXQ6vu27ETMpYsEMAsisQ+GqJ4e1TPvSNfdOPF0no=
Expand All @@ -41,20 +63,48 @@ github.com/shabbyrobe/xmlwriter v0.0.0-20200208144257-9fca06d00ffa h1:2cO3RojjYl
github.com/shabbyrobe/xmlwriter v0.0.0-20200208144257-9fca06d00ffa/go.mod h1:Yjr3bdWaVWyME1kha7X0jsz3k2DgXNa1Pj3XGyUAbx8=
github.com/signintech/gopdf v0.20.0 h1:a1rArIMmQCAFzjjCqXPgxynTPkytMccPuGZlUU8Jorw=
github.com/signintech/gopdf v0.20.0/go.mod h1:wrLtZoWaRNrS4hphED0oflFoa6IWkOu6M3nJjm4VbO4=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tealeg/xlsx/v3 v3.3.6 h1:b0SPORnNa8BDbFEujljp2IpTDVse3D+Ad5IaMz7KUL8=
github.com/tealeg/xlsx/v3 v3.3.6/go.mod h1:KV4FTFtvGy0TBlOivJLZu/YNZk6e0Qtk7eOSglWksuA=
github.com/u2takey/ffmpeg-go v0.5.0 h1:r7d86XuL7uLWJ5mzSeQ03uvjfIhiJYvsRAJFCW4uklU=
github.com/u2takey/ffmpeg-go v0.5.0/go.mod h1:ruZWkvC1FEiUNjmROowOAps3ZcWxEiOpFoHCvk97kGc=
github.com/u2takey/go-utils v0.3.1 h1:TaQTgmEZZeDHQFYfd+AdUT1cT4QJgJn/XVPELhHw4ys=
github.com/u2takey/go-utils v0.3.1/go.mod h1:6e+v5vEZ/6gu12w/DC2ixZdZtCrNokVxD0JUklcqdCs=
gocv.io/x/gocv v0.25.0/go.mod h1:Rar2PS6DV+T4FL+PM535EImD/h13hGVaHhnCu1xarBs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4=
golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U=
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
2 changes: 2 additions & 0 deletions pkg/files/image_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func (i *ImageFactory) NewFile(f string) (File, error) {
return images.NewTiff(), nil
case images.BMP:
return images.NewBmp(), nil
case images.AVIF:
return images.NewAvif(), nil
default:
return nil, fmt.Errorf("type file %s not recognized", f)
}
Expand Down
88 changes: 88 additions & 0 deletions pkg/files/images/avif.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package images

import (
"fmt"
"io"
"slices"
"strings"
)

// Avif struct implements the File and Image interface from the files pkg.
type Avif struct {
compatibleFormats map[string][]string
compatibleMIMETypes map[string][]string
}

// NewAvif returns a pointer to a Avif instance.
// The Avif object is set with a map with list of supported file formats.
func NewAvif() *Avif {
a := Avif{
compatibleFormats: map[string][]string{
"Image": {
JPG,
JPEG,
PNG,
GIF,
WEBP,
TIFF,
BMP,
},
},

compatibleMIMETypes: map[string][]string{
"Image": {
JPG,
JPEG,
PNG,
GIF,
WEBP,
TIFF,
BMP,
},
},
}

return &a
}

// SupportedFormats returns a map with a slice of supported files.
// Every key of the map represents the kind of a file.
func (a *Avif) SupportedFormats() map[string][]string {
return a.compatibleFormats
}

// SupportedMIMETypes returns a map with a slice of supported MIME types.
func (a *Avif) SupportedMIMETypes() map[string][]string {
return a.compatibleMIMETypes
}

// ConvertTo method converts a given file to a target format.
// This method returns a file in form of a slice of bytes.
func (a *Avif) ConvertTo(fileType, subType string, file io.Reader) (io.Reader, error) {
compatibleFormats, ok := a.SupportedFormats()[fileType]
if !ok {
return nil, fmt.Errorf("ConvertTo: file type not supported: %s", fileType)
}

if !slices.Contains(compatibleFormats, subType) {
return nil, fmt.Errorf("ConvertTo: file sub-type not supported: %s", subType)
}

switch strings.ToLower(fileType) {
case imageType:
convertedImage, err := convertToImage(subType, file)
if err != nil {
return nil, err
}

return convertedImage, nil
default:
return nil, fmt.Errorf("not supported file type %s", fileType)
}
}

// ImageType returns the file format of the current image.
// This method implements the Image interface.
func (a *Avif) ImageType() string {
return AVIF
}
12 changes: 4 additions & 8 deletions pkg/files/images/bmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func NewBmp() *Bmp {
b := Bmp{
compatibleFormats: map[string][]string{
"Image": {
AVIF,
JPG,
JPEG,
PNG,
Expand All @@ -35,6 +36,7 @@ func NewBmp() *Bmp {
},
compatibleMIMETypes: map[string][]string{
"Image": {
AVIF,
JPG,
JPEG,
PNG,
Expand Down Expand Up @@ -79,18 +81,12 @@ func (b *Bmp) ConvertTo(fileType, subType string, file io.Reader) (io.Reader, er

switch strings.ToLower(fileType) {
case imageType:
img, err := bmp.Decode(file)
convertedImage, err := convertToImage(subType, file)
if err != nil {
return nil, err
}

result, err = convertToImage(subType, img)
if err != nil {
return nil, fmt.Errorf(
"ConvertTo: error at converting image to another format: %w",
err,
)
}
return convertedImage, nil
case documentType:
img, err := bmp.Decode(file)
if err != nil {
Expand Down
12 changes: 4 additions & 8 deletions pkg/files/images/gif.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func NewGif() *Gif {
g := Gif{
compatibleFormats: map[string][]string{
"Image": {
AVIF,
JPG,
JPEG,
PNG,
Expand All @@ -34,6 +35,7 @@ func NewGif() *Gif {
},
compatibleMIMETypes: map[string][]string{
"Image": {
AVIF,
JPG,
JPEG,
PNG,
Expand Down Expand Up @@ -78,18 +80,12 @@ func (g *Gif) ConvertTo(fileType, subType string, file io.Reader) (io.Reader, er

switch strings.ToLower(fileType) {
case imageType:
img, err := gif.Decode(file)
convertedImage, err := convertToImage(subType, file)
if err != nil {
return nil, err
}

result, err = convertToImage(subType, img)
if err != nil {
return nil, fmt.Errorf(
"ConvertTo: error at converting image to another format: %w",
err,
)
}
return convertedImage, nil
case documentType:
img, err := gif.Decode(file)
if err != nil {
Expand Down
Loading

0 comments on commit a9852aa

Please sign in to comment.