Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG to PNG fails #136

Closed
autcrock opened this issue Sep 12, 2016 · 2 comments
Closed

SVG to PNG fails #136

autcrock opened this issue Sep 12, 2016 · 2 comments

Comments

@autcrock
Copy link

autcrock commented Sep 12, 2016

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

@Twinside
Copy link
Owner

Twinside commented Sep 12, 2016

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

@autcrock
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants