{"id":66816,"date":"2025-02-07T03:01:00","date_gmt":"2025-02-06T17:01:00","guid":{"rendered":"https:\/\/www.rjmprogramming.com.au\/ITblog\/?p=66816"},"modified":"2025-02-12T16:25:03","modified_gmt":"2025-02-12T06:25:03","slug":"python-cowsay-api-cartoon-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/python-cowsay-api-cartoon-tutorial\/","title":{"rendered":"Python Cowsay API Cartoon Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"https:\/\/www.rjmprogramming.com.au\/cowsay.php\" rel=\"noopener\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Python Cowsay API Cartoon Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/cowsay_cartoon.gif\" title=\"Python Cowsay API Cartoon Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">Python Cowsay API Cartoon Tutorial<\/p><\/div>\n<p>We&#8217;ve long been interested in online web application ideas that end up with a half decent cartoon the user can create, and share, themselves.  &#8220;Half decent&#8221; becomes &#8220;fully decent&#8221; with a user who has a great imagination.  And so, onto yesterday&#8217;s <a title='Python Cowsay API Primer Tutorial' href='#pcapipt'>Python Cowsay API Primer Tutorial<\/a>&#8216;s start with interfacing to the great <a target=\"_blank\" title='Python cowsay' href='https:\/\/pypi.org\/project\/cowsay\/' rel=\"noopener\"><i>cowsay<\/i><\/a> Python API \/ Command-line tool we access via the PHP <a target=\"_blank\" title='PHP exec() method information' href='http:\/\/php.net\/manual\/en\/function.exec.php' rel=\"noopener\">exec<\/a> method conduit to our AlmaLinux Apache\/PHP\/MySql Linux web server, today we&#8217;ve extended that &#8230;<\/p>\n<ul>\n<li>&#8220;proof of concept&#8221; thinking &#8230; onto &#8230;<\/li>\n<li>cartoon creation &#8220;smarts&#8221; &#8230; starting with <font size=1>(also egged on here by mobile platform problems with monospaced fonts, it seems like)<\/font> &#8230;<\/li>\n<li>allowing a tabular display of our <i>cowsay<\/i> components &#8230; into &#8230;<\/li>\n<li>table cells horizontally aligned (and so, less vulnerable to monospacing inaccuracies) &#8230; also allowing &#8230;<\/li>\n<li>within any table cell there is a topmost th table cell wording part above a <i>cowsay<\/i> character td cell lower part &#8230;<\/li>\n<li>&#8220;half decent&#8221; looking via <font color=blue>static CSS<\/font> &#8230;<br \/>\n&lt;?php echo &#8221;<br \/>\n<code><br \/>\n&lt;style&gt;<br \/>\n margin: 0 0 0 0;<br \/>\n padding: 0 0 0 0;<br \/>\n <font color=blue>tr { vertical-align: top; }<br \/>\n td { vertical-align: top; }<br \/>\n th { vertical-align: top; }<\/font><br \/>\n * { font-family:'Courier New',Courier,monospace; }<br \/>\n .img-hor { \/\/ thanks to https:\/\/stackoverflow.com\/questions\/32875695\/flip-mirror-an-image-horizontally-vertically-with-css<br \/>\n        -moz-transform: scaleX(-1);<br \/>\n        -o-transform: scaleX(-1);<br \/>\n        -webkit-transform: scaleX(-1);<br \/>\n        transform: scaleX(-1);<br \/>\n        filter: FlipH;<br \/>\n        -ms-filter: 'FlipH';<br \/>\n }<br \/>\n .img-ver { \/\/ thanks to https:\/\/stackoverflow.com\/questions\/32875695\/flip-mirror-an-image-horizontally-vertically-with-css<br \/>\n        -moz-transform: scaleY(-1);<br \/>\n        -o-transform: scaleY(-1);<br \/>\n        -webkit-transform: scaleY(-1);<br \/>\n        transform: scaleY(-1);<br \/>\n        filter: FlipV;<br \/>\n        -ms-filter: 'FlipV';<br \/>\n }<br \/>\n<br \/>\n .glow {<br \/>\n  -webkit-animation: glow 1s linear infinite alternate;<br \/>\n  -moz-animation: glow 1s linear infinite alternate;<br \/>\n  animation: glow 1s linear infinite alternate;<br \/>\n }<br \/>\n<br \/>\n \/* Thanks to https:\/\/www.w3schools.com\/howto\/tryit.asp?filename=tryhow_css_glowing_text *\/<br \/>\n<br \/>\n @-webkit-keyframes glow {<br \/>\n  from {<br \/>\n    box-shadow: 0 0 3px #fff, 0 0 5px #fff, 0 0 37px #e60073, 0 0 9px #e60073, 0 0 11px #e60073, 0 0 13px #e60073, 0 0 15px #e60073;<br \/>\n  }<br \/>\n<br \/>\n  to {<br \/>\n    box-shadow: 0 0 24px #fff, 0 0 6px #ff4da6, 0 0 8px #ff4da6, 0 0 10px #ff4da6, 0 0 12px #ff4da6, 0 0 14px #ff4da6, 0 0 16px #ff4da6;<br \/>\n  }<br \/>\n }<br \/>\n<br \/>\nth[id$='0'] {<br \/>\n    background: rgba(224,240,240,0.6); \/\/#e0f0f0;<br \/>\n}<br \/>\n<br \/>\nth[id$='1'] {<br \/>\n    background: rgba(225,241,241,0.6); \/\/#e1f1f1;<br \/>\n}<br \/>\n<br \/>\nth[id$='2'] {<br \/>\n    background: rgba(226,242,242,0.6); \/\/#e2f2f2;<br \/>\n}<br \/>\n<br \/>\nth[id$='3'] {<br \/>\n    background: rgba(227,243,243,0.6); \/\/#e3f3f3;<br \/>\n}<br \/>\n<br \/>\nth[id$='4'] {<br \/>\n    background: rgba(228,244,244,0.6); \/\/#e4f4f4;<br \/>\n}<br \/>\n<br \/>\nth[id$='5'] {<br \/>\n    background: rgba(229,245,245,0.6); \/\/#e5f5f5;<br \/>\n}<br \/>\n<br \/>\nth[id$='6'] {<br \/>\n    background: rgba(230,246,246,0.6); \/\/#e6f6f6;<br \/>\n}<br \/>\n<br \/>\nth[id$='7'] {<br \/>\n    background: rgba(231,247,247,0.6); \/\/#e7f7f7;<br \/>\n}<br \/>\n<br \/>\nth[id$='8'] {<br \/>\n    background: rgba(232,248,248,0.6); \/\/#e2f2f2;<br \/>\n}<br \/>\n<br \/>\nth[id$='9'] {<br \/>\n    background: rgba(233,249,249,0.6); \/\/#e9f9f9;<br \/>\n}<br \/>\n<br \/>\ntd[id$='0'] {<br \/>\n    background: rgba(240,240,240,0.3); \/\/#f0f0f0;<br \/>\n    text-shadow:-1px 1px 1px #ff2d90;<br \/>\n}<br \/>\n<br \/>\ntd[id$='1'] {<br \/>\n    background: rgba(241,241,241,0.3); \/\/#f1f1f1;<br \/>\n    text-shadow:-1px 1px 1px #ff2d91;<br \/>\n    float: bottom;<br \/>\n}<br \/>\n<br \/>\ntd[id$='2'] {<br \/>\n    background: rgba(242,242,242,0.3); \/\/#f2f2f2;<br \/>\n    text-shadow:-1px 1px 1px #ff2d92;<br \/>\n}<br \/>\n<br \/>\ntd[id$='3'] {<br \/>\n    background: rgba(243,243,243,0.3); \/\/#f3f3f3;<br \/>\n    text-shadow:-1px 1px 1px #ff2d93;<br \/>\n}<br \/>\n<br \/>\ntd[id$='4'] {<br \/>\n    background: rgba(244,244,244,0.3); \/\/#f4f4f4;<br \/>\n    text-shadow:-1px 1px 1px #ff2d94;<br \/>\n}<br \/>\n<br \/>\ntd[id$='5'] {<br \/>\n    background: rgba(245,245,245,0.3); \/\/#f5f5f5;<br \/>\n    text-shadow:-1px 1px 1px #ff2d95;<br \/>\n}<br \/>\n<br \/>\ntd[id$='6'] {<br \/>\n    background: rgba(246,246,246,0.3); \/\/#f6f6f6;<br \/>\n    text-shadow:-1px 1px 1px #ff2d96;<br \/>\n}<br \/>\n<br \/>\ntd[id$='7'] {<br \/>\n    background: rgba(247,247,247,0.3); \/\/#f7f7f7;<br \/>\n    text-shadow:-1px 1px 1px #ff2d97;<br \/>\n}<br \/>\n<br \/>\ntd[id$='8'] {<br \/>\n    background: rgba(248,248,248,0.3); \/\/#f8f8f8;<br \/>\n    text-shadow:-1px 1px 1px #ff2d98;<br \/>\n}<br \/>\n<br \/>\ntd[id$='9'] {<br \/>\n    background: rgba(249,249,249,0.3); \/\/#f9f9f9;<br \/>\n    text-shadow:-1px 1px 1px #ff2d99;<br \/>\n}<br \/>\n<br \/>\ntable tbody tr:first-child {<br \/>\n    background: transparent; \/\/#f6f6e6;<br \/>\n}<br \/>\n&lt;\/style&gt;<br \/>\n<\/code><br \/>\n&#8220;; ?&gt;<br \/>\n &#8230; and then &#8230;\n<\/li>\n<li>whenever new cell content happens <i>padding-top<\/i> adding CSS Javascript DOM nuanced display logic via &#8230;<br \/>\n&lt;?php echo &#8221;<br \/>\n<code><br \/>\n   function paddingtopit() {<br \/>\n      var maxtwo=0, thistwo=0;<br \/>\n      var thhs=[], tdhs=[], it=0;<br \/>\n      var thdids=[];<br \/>\n      \/\/trthtd1<br \/>\n      \/\/trtdtd1<br \/>\n      var tds=document.getElementsByTagName('td');<br \/>\n      for (it=0; it&lt;tds.length; it++) {<br \/>\n         if (('' + tds[it].id).indexOf('trtdtd') != -1) {<br \/>\n           if (('' + tds[it].style.paddingTop).replace(\/^null\/g,'').replace(\/^undefined\/g,'').trim() != '') {<br \/>\n             tds[it].style.paddingTop='0px';<br \/>\n           }<br \/>\n         }<br \/>\n      }<br \/>\n      for (it=0; it&lt;tds.length; it++) {<br \/>\n         if (('' + tds[it].id).indexOf('trtdtd') != -1) {<br \/>\n           tdhs.push(eval('' + tds[it].getBoundingClientRect().height));<br \/>\n           thdids.push('' + tds[it].id);<br \/>\n         }<br \/>\n      }<br \/>\n      var ths=document.getElementsByTagName('th');<br \/>\n      for (it=0; it&lt;ths.length; it++) {<br \/>\n         if (('' + ths[it].id).indexOf('trthtd') != -1) {<br \/>\n           thhs.push(eval('' + ths[it].getBoundingClientRect().height));<br \/>\n           thistwo=eval(thhs[it] + tdhs[it]);<br \/>\n           if (thistwo &gt; maxtwo) { maxtwo=thistwo; }<br \/>\n         }<br \/>\n      }<br \/>\n      for (it=0; it&lt;tdhs.length; it++) {<br \/>\n           thistwo=eval(thhs[it] + tdhs[it]);<br \/>\n           if (thistwo &lt; maxtwo) {<br \/>\n              document.getElementById(thdids[it]).style.paddingTop='' + eval(maxtwo - thistwo) + 'px';<br \/>\n           }<br \/>\n      }<br \/>\n   }<br \/>\n<\/code><br \/>\n&#8220;; ?&gt;<br \/>\n &#8230; so that &#8230;\n<\/li>\n<li>cartoons present with &#8220;speech bubble&#8221; wording aligned to the top in our &#8220;cells&#8221; (ie. th contenteditable=true editable wording on top of td horizontal flip (double click) and\/or vertical flop (right click) editable lower part) with those characters aligned to the bottom<\/li>\n<\/ul>\n<p> &#8230; in <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/cowsay.php--GETME\" rel=\"noopener\">our changed<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/cowsay.php--GETME\" rel=\"noopener\">&#8220;third draft&#8221;<\/a> <a target=\"_blank\" href=\"https:\/\/www.rjmprogramming.com.au\/cowsay.php\" rel=\"noopener\">Cartoon creation and email sharing capable<\/a> PHP web application you can also <a href='#ifcart'>try below<\/a>.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=\"_blank\" href='\/\/www.rjmprogramming.com.au\/ITblog\/python-cowsay-api-cartoon-tutorial\/' rel=\"noopener\">Python Cowsay API Cartoon Tutorial<\/a>.<\/p-->\n<hr>\n<p id='pcapipt'>Previous relevant <a target=\"_blank\" title='Python Cowsay API Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/python-cowsay-api-primer-tutorial\/' rel=\"noopener\">Python Cowsay API Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"https:\/\/www.rjmprogramming.com.au\/cowsay.php\" rel=\"noopener\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Python Cowsay API Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/cowsay.gif\" title=\"Python Cowsay API Primer Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">Python Cowsay API Primer Tutorial<\/p><\/div>\n<p>We discovered an interesting Open Source Python API \/ Command-line tool called <a target=\"_blank\" title='Python cowsay' href='https:\/\/pypi.org\/project\/cowsay\/' rel=\"noopener\"><i>cowsay<\/i><\/a> which we installed up at our AlmaLinux web server via &#8230;<\/p>\n<p><code><br \/>\npip install cowsay<br \/>\n<\/code><\/p>\n<p> &#8230; with an integration purpose in mind, so thanks.  Before many readers&#8217; time indeed, but some may remember those cute banner printouts that told you who owned the next printout on a spooling &#8220;crude graphics&#8221; printout in the late 70&#8217;s &#8230; well <i>cowsay<\/i> encapsulates those heady days (and who can forget punch cards)?!   Before integration, though, we want to test it via a new PHP supervisor on <a target=\"_blank\" title='PHP exec() method information' href='http:\/\/php.net\/manual\/en\/function.exec.php' rel=\"noopener\">exec<\/a> method Linux command line interfacings to <i>cowsay<\/i>.<\/p>\n<p>So we started, with <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/cowsay.php_GETME\" rel=\"noopener\">this &#8220;first draft&#8221;<\/a> getting places and then <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/cowsay.php-GETME\" rel=\"noopener\">this &#8220;second draft&#8221;<\/a> with a <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/cowsay.php-GETME\" rel=\"noopener\">little more sophistication<\/a> to leave the day with <a target=\"_blank\" href=\"https:\/\/www.rjmprogramming.com.au\/cowsay.php\" rel=\"noopener\">this interfacer<\/a> &#8230;<\/p>\n<p><iframe id=ifcart style=\"width:100%;height:800px;\" src=\"\/\/www.rjmprogramming.com.au\/cowsay.php?rand=765786\"><\/iframe><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d66808' onclick='var dv=document.getElementById(\"d66808\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/api\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d66808' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d66816' onclick='var dv=document.getElementById(\"d66816\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/cartoon\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d66816' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ve long been interested in online web application ideas that end up with a half decent cartoon the user can create, and share, themselves. &#8220;Half decent&#8221; becomes &#8220;fully decent&#8221; with a user who has a great imagination. And so, onto &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/python-cowsay-api-cartoon-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,37],"tags":[72,88,105,4119,1580,1824,230,2442,5093,3647,405,2223,2224,451,1828,452,576,611,652,5091,2997,5092,877,932,2550,3120,997,5090,1012,1075,1179,2398,5088,5089,1238,3312,3907,1254,1262,3489,1319,1802,2308],"class_list":["post-66816","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-align","tag-api","tag-ascii","tag-cartoon","tag-cell","tag-character","tag-column","tag-contenteditable","tag-courier-new","tag-drawing","tag-exec","tag-flip","tag-flop","tag-font","tag-font-family","tag-form","tag-html","tag-install","tag-javascript","tag-monospace","tag-monospaced","tag-monospacing","tag-open-source","tag-php","tag-pip","tag-printout","tag-programming","tag-punchcards","tag-python","tag-row","tag-speech","tag-speech-bubble","tag-spool","tag-spooling","tag-table","tag-tabular","tag-td","tag-text","tag-textarea","tag-th","tag-tutorial","tag-vertical-align","tag-wording"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/66816"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=66816"}],"version-history":[{"count":9,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/66816\/revisions"}],"predecessor-version":[{"id":66911,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/66816\/revisions\/66911"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=66816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=66816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=66816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}