mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 10:55:30 -04:00
Add helper methods for thumbnail generation
This commit is contained in:
parent
968c2f4ad5
commit
8ac89c420c
@ -69,7 +69,7 @@ class Entry
|
||||
|
||||
def cover_url
|
||||
return "#{Config.current.base_url}img/icon.png" if @err_msg
|
||||
url = "#{Config.current.base_url}api/page/#{@book.id}/#{@id}/1"
|
||||
url = "#{Config.current.base_url}api/cover/#{@book.id}/#{@id}"
|
||||
TitleInfo.new @book.dir do |info|
|
||||
info_url = info.entry_cover_url[@title]?
|
||||
unless info_url.nil? || info_url.empty?
|
||||
@ -207,4 +207,23 @@ class Entry
|
||||
def started?(username)
|
||||
load_progress(username) > 0
|
||||
end
|
||||
|
||||
def generate_thumbnail : Image?
|
||||
return if @err_msg
|
||||
|
||||
img = read_page(1).not_nil!
|
||||
begin
|
||||
thumbnail = ImageSize.resize img.data, height: 300
|
||||
img.data = thumbnail
|
||||
Storage.default.save_thumbnail @id, img
|
||||
rescue e
|
||||
Logger.warn "Failed to generate thumbnail for entry #{@id}. #{e}"
|
||||
end
|
||||
|
||||
img
|
||||
end
|
||||
|
||||
def get_thumbnail : Image?
|
||||
Storage.default.get_thumbnail @id
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user