<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2014:03:17</title>
        <description></description>
        <link>https://baszerr.eu/</link>
        <lastBuildDate>Fri, 01 May 2026 08:53:13 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://baszerr.eu/</link>
        </image>
        <item>
            <title>source_to_image</title>
            <link>https://baszerr.eu/doku.php?id=blog:2014:03:17:source_to_image</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;source_to_image&quot;&gt;2014-03-17 - source to image&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
few days ago i was preparing C++ test for a training i&amp;#039;ll be doing for coworkers. of course (almost) all questions had source code attached with questions like “is this code correct?”, “does it leak memory?”, etc… unfortunately for me, system that we use for preparing such a trainings does not provide syntax highlighting, which make reading problematic. the accepted solution is to insert such a questions as images, instead of text. so i could either do tens of print-screens… or write a script. :)
&lt;/p&gt;

&lt;p&gt;
script does few steps:
&lt;/p&gt;
&lt;pre class=&quot;code sh&quot;&gt;enscript --color -f Courier12 -B -1 --highlight=cpp -h -o tmp.ps input.cpp
gs -sDEVICE=jpeg -r400 -sPAPERSIZE=a4 -dBATCH -dNOPAUSE -sOutputFile=tmp.png tmp.ps
convert tmp.png -trim -border 10 -scale &amp;quot;50%&amp;quot; out.png&lt;/pre&gt;

&lt;p&gt;
(working script &lt;a href=&quot;https://github.com/el-bart/mini/blob/master/src2img&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/el-bart/mini/blob/master/src2img&quot; rel=&quot;ugc nofollow&quot;&gt;scr2img on github&lt;/a&gt;)
&lt;/p&gt;

&lt;p&gt;
first line produces colored postscript from source. its nice, but i&amp;#039;ve needed png, so next line creates one with ghostscript (note 400dpi!). last one removes extra white spaces, adds a border… and scales image down to 50% (aka: 200dpi). looks weird, but this is the only way to get reasonable quality of an output - sorry folks. :/
&lt;/p&gt;

&lt;p&gt;
example source:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;using&lt;/span&gt; std&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw3&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;using&lt;/span&gt; std&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; main&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw3&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; endl&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw3&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;bye bye world&amp;quot;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; endl&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
produces the following image: &lt;br/&gt;

&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2014%3A03%3A17%3Asource_to_image&amp;amp;media=blog:2014:03:17:test.png&quot; class=&quot;media&quot; title=&quot;blog:2014:03:17:test.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?w=300&amp;amp;tok=a968d1&amp;amp;media=blog:2014:03:17:test.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;source code as an image&quot; alt=&quot;source code as an image&quot; width=&quot;300&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
imperfect, but good enough for me. :D note that script itself can be optimized as well – most of the times temporary file is not really needed.
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 15 Jun 2021 20:08:52 +0000</pubDate>
        </item>
    </channel>
</rss>
