Twinside / Juicy.Pixels

Haskell library to load & save pictures

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SVG to PNG fails

autcrock opened this issue · comments

Hi there.

The attached SVG converts to a blank PNG using the code below under stackage nightly-2016-09-01. Both files are in the attachment.

The SVG displays correctly under Chrome and the Atom editor SVG viewer. Atom also correctly converts the file to a PNG.

Please let me know what you think. If it's a Rasterific problem I'll pass it on to them.

Thanks

Mike Thomas.

svgRowsToFile :: [(Int, String)] -> String -> String -> (Double, Double) -> (Int, Int, Int) -> IO()
svgRowsToFile rows svgFileName pngFileName tlxy pixels@(l,x,y) =
    do
        h <- openFile svgFileName WriteMode
        hPutStrLn h ( "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.2 Tiny\" height=\"" ++ (show x) ++ "\" width=\"" ++ (show y) ++ "\">\n" )
        mapM (hPutStrLn h) (map (makeTransformedPathString tlxy pixels) rows)
        hPutStrLn h "</svg>\n"
        hClose h
        f <- loadSvgFile svgFileName
        case f of
             Nothing -> putStrLn ("svgRowsToFile: Error while loading: " ++ svgFileName)
             Just doc -> do
                (finalImage, _) <- renderSvgDocument emptyFontCache Nothing 96 doc
                writePng pngFileName finalImage

svgRowsToFile :: [(Int, String)] -> String -> String -> (Double, Double) -> (Int, Int, Int) -> IO()
svgRowsToFile rows svgFileName pngFileName tlxy pixels@(l,x,y) =
    do
        h <- openFile svgFileName WriteMode
        hPutStrLn h ( "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.2 Tiny\" height=\"" ++ (show x) ++ "\" width=\"" ++ (show y) ++ "\">\n" )
        mapM (hPutStrLn h) (map (makeTransformedPathString tlxy pixels) rows)
        hPutStrLn h "</svg>\n"
        hClose h
        f <- loadSvgFile svgFileName
        case f of
             Nothing -> putStrLn ("svgRowsToFile: Error while loading: " ++ svgFileName)
             Just doc -> do
                (finalImage, _) <- renderSvgDocument emptyFontCache Nothing 96 doc
                writePng pngFileName finalImage

SVG_PNG_MJT_20160912.zip

You have a space in front of your M path command, which is not handled correctly in svg-tree.

New ticket: Twinside/svg-tree#10

Thanks!