Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
liber
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
ale
liber
Commits
9285ee23
Commit
9285ee23
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
use the image package to generate thumbnails instead of "convert"
parent
0910a960
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
web.go
+27
-4
27 additions, 4 deletions
web.go
with
27 additions
and
4 deletions
web.go
+
27
−
4
View file @
9285ee23
...
...
@@ -6,17 +6,22 @@ import (
"flag"
"fmt"
"html/template"
"image"
_
"image/gif"
"image/jpeg"
_
"image/png"
"io"
"log"
"net/http"
"net/url"
"os
/exec
"
"os"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/gorilla/mux"
"github.com/nfnt/resize"
)
var
(
...
...
@@ -261,7 +266,26 @@ func (s *uiServer) handleShowCover(book *Book, w http.ResponseWriter, req *http.
http
.
ServeContent
(
w
,
req
,
""
,
time
.
Time
{},
f
)
}
const
thumbnailSize
=
"150x150"
var
thumbnailSize
uint
=
150
func
makeThumbnail
(
inputfile
string
)
([]
byte
,
error
)
{
file
,
err
:=
os
.
Open
(
inputfile
)
if
err
!=
nil
{
return
nil
,
err
}
defer
file
.
Close
()
img
,
_
,
err
:=
image
.
Decode
(
file
)
if
err
!=
nil
{
return
nil
,
err
}
thumb
:=
resize
.
Thumbnail
(
thumbnailSize
,
thumbnailSize
,
img
,
resize
.
Lanczos2
)
var
buf
bytes
.
Buffer
if
err
:=
jpeg
.
Encode
(
&
buf
,
thumb
,
&
jpeg
.
Options
{
Quality
:
65
});
err
!=
nil
{
return
nil
,
err
}
return
buf
.
Bytes
(),
nil
}
func
(
s
*
uiServer
)
handleShowThumbnail
(
book
*
Book
,
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
if
book
.
CoverPath
==
""
{
...
...
@@ -287,8 +311,7 @@ func (s *uiServer) handleShowThumbnail(book *Book, w http.ResponseWriter, req *h
}
defer
cachedFile
.
Close
()
data
,
err
:=
exec
.
Command
(
"convert"
,
book
.
CoverPath
,
"-geometry"
,
thumbnailSize
,
"-quality"
,
"60"
,
"jpeg:-"
)
.
Output
()
data
,
err
:=
makeThumbnail
(
s
.
storage
.
Abs
(
book
.
CoverPath
))
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
...
...
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