Created
April 8, 2015 17:08
-
-
Save lierdakil/f8b993afe00794f4457a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Codec.Picture | |
import Codec.Picture.Types | |
import Graphics.PDF | |
import Codec.Picture.Saving | |
import Data.ByteString.Lazy as B | |
import System.IO (hClose) | |
import System.IO.Temp | |
import System.Environment | |
main :: IO () | |
main = do | |
[inp,outp] <- getArgs | |
Right image <- readImage inp | |
let w = dynamicMap imageWidth image | |
h = dynamicMap imageHeight image | |
rect = PDFRect 0 0 w h | |
withSystemTempFile "img2pdf.jpg" $ \p hndl -> do | |
B.hPut hndl $ imageToJpg 100 image | |
hClose hndl | |
Right jpgf <- readJpegFile p | |
runPdf outp standardDocInfo rect $ do | |
page <- addPage Nothing | |
img <- createPDFJpeg jpgf | |
drawWithPage page $ withNewContext $ drawXObject img |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment