diff --git a/README b/README index e8a9d27..0cb7f3e 100644 --- a/README +++ b/README @@ -15,18 +15,17 @@ In order to run Trantor, you need to install the following packages: * Go language * Epub development library * Mongodb -* Imagemagick (for resize covers) * Bazaar * Mercurial * Git (necessary only if you want to deal with the repository) Under Debian Wheezy you can simply run: -# aptitude install golang-go git mercurial bzr libepub-dev mongodb imagemagick +# aptitude install golang-go git mercurial bzr libepub-dev mongodb Yo also need to install go dependences: -# go get labix.org/v2/mgo/bson labix.org/v2/mgo/ github.com/gorilla/sessions github.com/gorilla/securecookie +# go get labix.org/v2/mgo/bson labix.org/v2/mgo/ github.com/gorilla/sessions github.com/gorilla/securecookie github.com/nfnt/resize == Installation == === For admins ("for developers" below) === diff --git a/config.go b/config.go index 44841a4..8318161 100644 --- a/config.go +++ b/config.go @@ -1,25 +1,30 @@ package main const ( - PORT = "8080" - DB_IP = "127.0.0.1" - DB_NAME = "trantor" - META_COLL = "meta" - BOOKS_COLL = "books" - TAGS_COLL = "tags" - USERS_COLL = "users" + PORT = "8080" + + DB_IP = "127.0.0.1" + DB_NAME = "trantor" + META_COLL = "meta" + BOOKS_COLL = "books" + TAGS_COLL = "tags" + USERS_COLL = "users" + PASS_SALT = "ImperialLibSalt" MINUTES_UPDATE_TAGS = 10 TAGS_DISPLAY = 50 SEARCH_ITEMS_PAGE = 20 NEW_ITEMS_PAGE = 50 - TEMPLATE_PATH = "templates/" - BOOKS_PATH = "books/" - COVER_PATH = "cover/" - NEW_PATH = "new/" - CSS_PATH = "css/" - JS_PATH = "js/" - IMG_PATH = "img/" - RESIZE_CMD = "/usr/bin/convert -resize 300 -quality 60 " - RESIZE_THUMB_CMD = "/usr/bin/convert -resize 60 -quality 60 " + + TEMPLATE_PATH = "templates/" + BOOKS_PATH = "books/" + COVER_PATH = "cover/" + NEW_PATH = "new/" + CSS_PATH = "css/" + JS_PATH = "js/" + IMG_PATH = "img/" + + IMG_WIDTH_BIG = 300 + IMG_WIDTH_SMALL = 60 + IMG_QUALITY = 80 ) diff --git a/cover.go b/cover.go new file mode 100644 index 0000000..a2b10a2 --- /dev/null +++ b/cover.go @@ -0,0 +1,122 @@ +package main + +import ( + "bytes" + "git.gitorious.org/go-pkg/epub.git" + "github.com/nfnt/resize" + "image" + "image/jpeg" + "log" + "os" + "regexp" + "strings" + "unicode/utf8" +) + +func GetCover(e *epub.Epub, title string) (string, string) { + /* Try first common names */ + for _, p := range []string{"cover.jpg", "Images/cover.jpg", "cover.jpeg", "cover1.jpg", "cover1.jpeg"} { + img := e.Data(p) + if len(img) != 0 { + return storeImg(img, title, ".jpg") + } + } + + /* search for img on the text */ + exp, _ := regexp.Compile("