mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-09-06 11:46:24 -07:00
Add PDF handling plugin
This commit is contained in:
parent
686c6fc004
commit
de2815c653
2 changed files with 30 additions and 1 deletions
|
@ -141,7 +141,9 @@ func registerLuaFunctions() {
|
|||
}, luar.New(l, upload), luar.New(l, post), lua.LString(board), lua.LString(filePath), lua.LString(thumbPath), lua.LString(catalogThumbPath))
|
||||
|
||||
errRet := l.CheckAny(-1)
|
||||
fmt.Println("Error:", errRet, errRet == nil)
|
||||
if errRet != nil && errRet.Type() != lua.LTNil {
|
||||
return errors.New(errRet.String())
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return 0
|
||||
|
|
27
sample-plugins/pdf_thumbnail.lua
Normal file
27
sample-plugins/pdf_thumbnail.lua
Normal file
|
@ -0,0 +1,27 @@
|
|||
-- requires ghostscript to be installed
|
||||
local os = require("os")
|
||||
|
||||
local cmd = "gs -q -sDEVICE=jpeg -dLastPage=1 -dNOPAUSE -r720 -g%dx%d -dPDFFitPage -dFIXEDMEDIA -dCompatibilityLevel=1.4 -o %q - < %q" -- width, height outpath, inpath
|
||||
|
||||
register_upload_handler(".pdf", function(upload, post, board, filePath, thumbPath, catalogThumbPath, infoEv, accessEv, errEv)
|
||||
-- width, height = get_pdf_dimensions(filePath)
|
||||
local boardcfg = board_config(board)
|
||||
upload.ThumbnailWidth = boardcfg.ThumbWidthReply
|
||||
upload.ThumbnailHeight = boardcfg.ThumbHeightReply
|
||||
if (post.IsTopPost) then
|
||||
upload.ThumbnailWidth = boardcfg.ThumbWidth
|
||||
upload.ThumbnailHeight = boardcfg.ThumbHeight
|
||||
status = os.execute(string.format(cmd, boardcfg.ThumbWidthCatalog, boardcfg.ThumbHeightCatalog, catalogThumbPath, filePath))
|
||||
if (status ~= 0) then
|
||||
return "unable to create PDF catalog thumbnail"
|
||||
end
|
||||
end
|
||||
|
||||
status = os.execute(string.format(cmd, upload.ThumbnailWidth, upload.ThumbnailHeight, thumbPath, filePath))
|
||||
if (status ~= 0) then
|
||||
return "unable to create PDF thumbnail"
|
||||
end
|
||||
|
||||
return nil
|
||||
end)
|
||||
set_thumbnail_ext(".pdf", ".jpg")
|
Loading…
Add table
Add a link
Reference in a new issue