Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
51ce888c
Commit
51ce888c
authored
1 year ago
by
Alena Petraki
Browse files
Options
Downloads
Patches
Plain Diff
Добавлена регистрация расширений для форматов изображений
parent
2b0a29fb
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pkg/images/imgconv/default_format.go
+8
-8
8 additions, 8 deletions
pkg/images/imgconv/default_format.go
pkg/images/imgconv/imgconv.go
+27
-15
27 additions, 15 deletions
pkg/images/imgconv/imgconv.go
pkg/images/imgconv/webp.go
+1
-1
1 addition, 1 deletion
pkg/images/imgconv/webp.go
with
36 additions
and
24 deletions
pkg/images/imgconv/default_format.go
+
8
−
8
View file @
51ce888c
...
...
@@ -12,17 +12,17 @@ import (
)
const
(
JPEG
=
"jpeg"
PNG
=
"png"
GIF
=
"gif"
TIFF
=
"tiff"
BMP
=
"bmp"
JPEG
Format
=
"jpeg"
PNG
Format
=
"png"
GIF
Format
=
"gif"
TIFF
Format
=
"tiff"
BMP
Format
=
"bmp"
)
func
init
()
{
RegisterFormatEncoder
(
JPEG
,
func
(
w
io
.
Writer
,
img
image
.
Image
)
error
{
return
jpeg
.
Encode
(
w
,
img
,
nil
)
})
RegisterFormatEncoder
(
PNG
,
func
(
w
io
.
Writer
,
img
image
.
Image
)
error
{
return
png
.
Encode
(
w
,
img
)
}
)
RegisterFormatEncoder
(
JPEG
,
func
(
w
io
.
Writer
,
img
image
.
Image
)
error
{
return
jpeg
.
Encode
(
w
,
img
,
nil
)
}
,
"jpg"
,
"jpeg"
)
RegisterFormatEncoder
(
PNG
,
png
.
Encode
,
"png"
)
RegisterFormatEncoder
(
GIF
,
func
(
w
io
.
Writer
,
img
image
.
Image
)
error
{
return
gif
.
Encode
(
w
,
img
,
nil
)
})
RegisterFormatEncoder
(
TIFF
,
func
(
w
io
.
Writer
,
img
image
.
Image
)
error
{
return
tiff
.
Encode
(
w
,
img
,
nil
)
})
RegisterFormatEncoder
(
BMP
,
func
(
w
io
.
Writer
,
img
image
.
Image
)
error
{
return
bmp
.
Encode
(
w
,
img
)
}
)
RegisterFormatEncoder
(
BMP
,
bmp
.
Encode
)
}
This diff is collapsed.
Click to expand it.
pkg/images/imgconv/imgconv.go
+
27
−
15
View file @
51ce888c
...
...
@@ -9,20 +9,24 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/errors"
)
var
builtinFormats
=
map
[
string
]
string
{
"jpg"
:
"jpeg"
,
"tif"
:
"tiff"
,
}
var
defaultFormatEncoderRegistry
=
make
(
map
[
string
]
EncodeFunc
)
type
(
EncodeFunc
func
(
w
io
.
Writer
,
img
image
.
Image
)
error
Format
string
)
type
EncodeFunc
func
(
w
io
.
Writer
,
img
image
.
Image
)
error
var
(
defaultFormatEncoderRegistry
=
make
(
map
[
Format
]
EncodeFunc
)
formatExtensions
=
make
(
map
[
string
]
Format
)
)
func
RegisterFormatEncoder
(
format
string
,
fn
EncodeFunc
)
{
func
RegisterFormatEncoder
(
format
Format
,
fn
EncodeFunc
,
extensions
...
string
)
{
defaultFormatEncoderRegistry
[
format
]
=
fn
for
_
,
ext
:=
range
extensions
{
formatExtensions
[
strings
.
TrimPrefix
(
strings
.
ToLower
(
ext
),
"."
)]
=
format
}
}
func
Encode
(
w
io
.
Writer
,
format
string
,
img
image
.
Image
)
error
{
func
Encode
(
w
io
.
Writer
,
format
Format
,
img
image
.
Image
)
error
{
encoder
,
ok
:=
defaultFormatEncoderRegistry
[
format
]
if
!
ok
{
return
errors
.
Errorf
(
"unknown format: %s"
,
format
)
...
...
@@ -55,11 +59,19 @@ func Open(filename string) (image.Image, string, error) {
return
img
,
ext
,
nil
}
func
NormalizeFormat
(
format
string
)
string
{
format
=
strings
.
ToLower
(
format
)
format
=
strings
.
TrimPrefix
(
format
,
"."
)
if
v
,
ok
:=
builtinFormats
[
format
];
ok
{
return
v
func
FormatFromExtension
(
ext
string
)
(
Format
,
error
)
{
ext
=
strings
.
TrimPrefix
(
strings
.
ToLower
(
ext
),
"."
)
if
f
,
ok
:=
formatExtensions
[
ext
];
ok
{
return
f
,
nil
}
return
format
return
""
,
errors
.
Errorf
(
"unsupported
format
"
)
}
//func NormalizeFormat(format string) string {
// format = strings.ToLower(format)
// format = strings.TrimPrefix(format, ".")
// //if v, ok := builtinFormats[format]; ok {
// // return v
// //}
// return format
//}
This diff is collapsed.
Click to expand it.
pkg/images/imgconv/webp.go
+
1
−
1
View file @
51ce888c
...
...
@@ -15,7 +15,7 @@ import (
)
const
(
WEBP
=
"webp"
WEBP
Format
=
"webp"
)
func
init
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment