Skip to content

Instantly share code, notes, and snippets.

@lierdakil
Created April 8, 2015 17:08
Show Gist options
  • Save lierdakil/f8b993afe00794f4457a to your computer and use it in GitHub Desktop.
Save lierdakil/f8b993afe00794f4457a to your computer and use it in GitHub Desktop.
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