{"id":66226,"date":"2025-01-10T03:01:00","date_gmt":"2025-01-09T17:01:00","guid":{"rendered":"https:\/\/www.rjmprogramming.com.au\/ITblog\/?p=66226"},"modified":"2025-01-10T06:02:10","modified_gmt":"2025-01-09T20:02:10","slug":"imagemagick-postscript-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/imagemagick-postscript-primer-tutorial\/","title":{"rendered":"ImageMagick Postscript Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"https:\/\/www.rjmprogramming.com.au\/imagemagick_fun.php\" rel=\"noopener\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"ImageMagick Postscript Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/imagemagick_fun.png\" title=\"ImageMagick Postscript Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">ImageMagick Postscript Primer Tutorial<\/p><\/div>\n<p>We could spend a lifetime telling you about the functionality of various <a target=\"_blank\" title='ImageMagick command line' href='http:\/\/www.imagemagick.org\/script\/command-line-tools.php' rel=\"noopener\">ImageMagick<\/a> guises and usages, further to the recent <a title='Imagick PHP Class Primer Tutorial' href='#iphpcpt'>Imagick PHP Class Primer Tutorial<\/a>.  We&#8217;ve decided to live a little separated from ImageMagick, or we just know we would have dreams about command line switches that turn into snakes or command lines turning into congo lines or command lines telling me about ten things I was never meant to do.<\/p>\n<p>The other day, though, we stumbled upon <a target=\"_blank\" title='Ghostscript and ImageMagick' href='https:\/\/usage.imagemagick.org\/text\/#ghostscript' rel=\"noopener\">a webpage<\/a> rekindling interest, which is far easier these days, with ImageMagick installed on our AlmaLinux web server here at RJM Programming.  Mind you, we also had it installed on the old CentOS web server, but it was as if, on CentOS, we had never &#8230;<\/p>\n<blockquote><p>\nReleased the <a target=\"_blank\" title='?' href='https:\/\/www.youtube.com\/playlist?list=PLYvHvDRWKWYwBQ01DRmedhUaddg2EmGFh' rel=\"noopener\">Kraken<\/a>\n<\/p><\/blockquote>\n<p> &#8230; with the lack of diskspace there on CentOS, also causing us unrest?!  No such problems on AlmaLinux, we give thanks for.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.rjmprogramming.com.au\/imagemagick_fun.gif\" rel=\"noopener\"><\/img><\/p>\n<p>Anyway, that webpage link got us thinking about where &#8230;<\/p>\n<ul>\n<li><a target=\"_blank\" title='Ghostscript' href='https:\/\/www.ghostscript.com\/' rel=\"noopener\">Ghostscript<\/a> &#8230; a PDF conversion specialist suite of software, you&#8217;ll often associate with &#8220;hardcode&#8221; printout functionality &#8230; interplays with &#8230;<\/li>\n<li><a target=\"_blank\" title='ImageMagick command line' href='http:\/\/www.imagemagick.org\/script\/command-line-tools.php' rel=\"noopener\">ImageMagick<\/a><\/li>\n<\/ul>\n<p> &#8230; and the command line had us hooked again.  So, we wrote a way you can get hooked too, effectively parsing a favoured ImageMagick &#8220;convert&#8221; <font size=1>(verb)<\/font> command into switches, a bit like parsing a language sentence, using PHP.<\/p>\n<blockquote><p>\nWhat?!!!!\n<\/p><\/blockquote>\n<p>Yes, it looks bad, as far as security goes, but we do some checks for malicious usage, in <a target=\"_blank\" href=\"https:\/\/www.rjmprogramming.com.au\/imagemagick_fun.php_GETME\" rel=\"noopener\">our &#8220;proof of concept&#8221;<\/a> <a target=\"_blank\" href=\"https:\/\/www.rjmprogramming.com.au\/imagemagick_fun.php\" rel=\"noopener\">ImageMagick command line, via PHP, channeller of Ghostscript ideas<\/a> image creator web application.<\/p>\n<p><iframe style=width:100%;height:1200px; src=\"\/\/www.rjmprogramming.com.au\/imagemagick_fun.php\" rel=\"noopener\"><\/iframe><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.rjmprogramming.com.au\/imagemagick_fun.jpg\" rel=\"noopener\"><\/img><\/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\/imagemagick-postscript-primer-tutorial\/' rel=\"noopener\">ImageMagick Postscript Primer Tutorial<\/a> ...<\/p-->\n<hr>\n<p id='iphpcpt'>Previous relevant <a target=\"_blank\" title='Imagick PHP Class Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/imagick-php-class-primer-tutorial\/' rel=\"noopener\">Imagick PHP Class 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\/PHP\/oil_painting_thumbnail.php\" rel=\"noopener\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Form Target Self Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/imagick_start.gif\" title=\"Form Target Self Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Imagick PHP Class Primer Tutorial<\/p><\/div>\n<p>We&#8217;re talking &#8220;class&#8221; today.  Up until now, regarding the great <a target=\"_blank\" title='ImageMagick software suite' href='https:\/\/www.imagemagick.org\/' rel=\"noopener\">ImageMagick<\/a> suite of software, and it&#8217;s interactions with PHP, we&#8217;ve &#8230;<\/p>\n<ul>\n<li>been using exec style calls of ImageMagick, mainly via it&#8217;s <i>convert<\/i> command line functionality, via our CentOS web server &#8230; but today we&#8217;re &#8230;<\/li>\n<li>introducing a (new for us, on AlmaLinux) modus operandi whereby a PHP <i>Imagick<\/i> class can be used to make calls to a myriad of calls within this software suite, with us just picking a few to introduce ourselves to &#8230; thanks to <a target=\"_blank\" title='https:\/\/www.php.net\/manual\/en\/book.imagick.php' href='https:\/\/www.php.net\/manual\/en\/book.imagick.php' rel=\"noopener\">https:\/\/www.php.net\/manual\/en\/book.imagick.php<\/a> and <a target=\"_blank\" title='https:\/\/www.php.net\/manual\/en\/imagick.contraststretchimage.php' href='https:\/\/www.php.net\/manual\/en\/imagick.contraststretchimage.php' rel=\"noopener\">https:\/\/www.php.net\/manual\/en\/imagick.contraststretchimage.php<\/a> primarily, here<\/li>\n<\/ul>\n<p> &#8230; in a <a target=\"_blank\" href=\"https:\/\/www.rjmprogramming.com.au\/PHP\/oil_painting_thumbnail.php_GETME\" rel=\"noopener\">first draft<\/a> <a target=\"_blank\" href=\"https:\/\/www.rjmprogramming.com.au\/PHP\/oil_painting_thumbnail.php\" rel=\"noopener\">not installed here on CentOS<\/a> <a target=\"_blank\" href=\"https:\/\/65.254.95.247\/PHP\/oil_painting_thumbnail.php\" rel=\"noopener\">but okay here with AlmaLinux<\/a>.  Am sure most people would concur that this is much more integrated approach for PHP &#8230;<\/p>\n<p><code><br \/>\n&lt;?php<br \/>\n\/\/ oil_painting_thumbnail.php<br \/>\n\/\/ RJM Programming - August, 2024<br \/>\n\/\/ Start using PHP Imagick class<br \/>\n$image=null;<br \/>\nif (!isset($_GET['image']) && !isset($_POST['image'])) {<br \/>\necho \"&lt;html&gt;&lt;head&gt;&lt;scr\" . \"ipt type=text\/javascript&gt; function ask() { var bsh=prompt('See the default brightness, saturation, hue settings, black point %, white point % and change as desired ... 100,0,100,90,95 is grayscale ... darkest 90% of pixels are turned black, the brightest 5% are made white, and those between 90% and 95% are grey-scaled', document.getElementById('brightness').value + ',' + document.getElementById('saturation').value + ',' + document.getElementById('hue').value + ',' + document.getElementById('blackpoint').value + ',' + document.getElementById('whitepoint').value); if (bsh != null) { if (eval('' + bsh.split(',').length) == 5) {  document.getElementById('brightness').value=bsh.split(',')[0]; document.getElementById('saturation').value=bsh.split(',')[1]; document.getElementById('hue').value=bsh.split(',')[2]; document.getElementById('blackpoint').value=bsh.split(',')[3]; document.getElementById('whitepoint').value=bsh.split(',')[4];   }   } return true;   } &lt;\/scr\" . \"ipt&gt;&lt;\/head&gt;&lt;body&gt;&lt;h1&gt;Imagick Ideas&lt;\/h1&gt;&lt;h3&gt;RJM Programming - August, 2024 ... thanks to https:\/\/www.php.net\/manual\/en\/book.imagick.php and https:\/\/www.php.net\/manual\/en\/imagick.contraststretchimage.php&lt;\/h3&gt;&lt;br&gt;&lt;br&gt;&lt;form action='.\/oil_painting_thumbnail.php' id=myform method=GET&gt;&lt;input type=hidden name=brightness value=100 id=brightness&gt;&lt;\/input&gt;&lt;input type=hidden name=saturation value=0 id=saturation&gt;&lt;\/input&gt;&lt;input type=hidden name=hue value=100 id=hue&gt;&lt;\/input&gt;&lt;input type=hidden name=blackpoint value=90 id=blackpoint&gt;&lt;\/input&gt;&lt;input type=hidden name=whitepoint value=95 id=whitepoint&gt;&lt;\/input&gt;&lt;input style='width:70%;' type=text placeholder='Image to process ...' name=image id=image value=''&gt;&lt;\/input&gt;&lt;br&gt;&lt;br&gt;&lt;input onclick=\\\" document.getElementById('myform').method='GET'; \\\"  type=submit style=background-color:orange; value=Negate&gt;&lt;\/input&gt;&nbsp;&lt;input style=background-color:yellow; onclick=\\\" if (ask()) { document.getElementById('myform').method='POST'; } \\\" type=submit value='Contrast Stretch'&gt;&lt;\/input&gt;&lt;\/form&gt;&lt;\/body&gt;&lt;\/html&gt;\";<br \/>\n} else {<br \/>\nif (isset($_GET['image'])) {<br \/>\n<br \/>\nheader('Content-type: image\/jpeg');<br \/>\n<br \/>\n\/\/Instantiate a new Imagick object<br \/>\n$image = new Imagick(realpath(urldecode($_GET['image'])));<br \/>\n$image-&gt;negateImage(false);<br \/>\n<br \/>\n\/\/ If 0 is provided as a width or height parameter,<br \/>\n\/\/ aspect ratio is maintained<br \/>\n$image-&gt;thumbnailImage(100, 0);<br \/>\n<br \/>\necho $image;<br \/>\nexit;<br \/>\n<br \/>\n} else {<br \/>\n\/\/Instantiate a new Imagick object<br \/>\n$image = new Imagick(realpath(urldecode($_POST['image'])));<br \/>\nlist($width, $height) = array_values ($image-&gt;getImageGeometry());<br \/>\n$b=(isset($_POST['brightness']) ? $_POST['brightness'] : '100');<br \/>\n$s=(isset($_POST['saturation']) ? $_POST['saturation'] : '0');<br \/>\n$h=(isset($_POST['hue']) ? $_POST['hue'] : '100');<br \/>\n$bp=(isset($_POST['blackpoint']) ? $_POST['blackpoint'] : '90');<br \/>\n$wp=(isset($_POST['whitepoint']) ? $_POST['whitepoint'] : '95');<br \/>\n$image-&gt;modulateImage($b, $s, $h);<br \/>\n$image-&gt;contrastStretchImage($width * $height * ($bp \/ 100.0), $width * $height * ($wp \/ 100.0));<br \/>\n$image-&gt;writeImage('example_thumbnail.jpg');<br \/>\necho \"&lt;html&gt;&lt;body&gt;&lt;p&gt;My Changed Image \" . urldecode($_POST['image']) . \" ... brightness \" . $b . \", saturation \" . $s . \", hue \" . $h . \", black point % \" . $bp . \"%, white point % \" . $wp . \"%&lt;\/p&gt;&lt;br&gt;&lt;img src='.\/example_thumbnail.jpg'&gt;&lt;\/img&gt;&lt;\/body&gt;&lt;\/html&gt;\";<br \/>\nexit;<br \/>\n<br \/>\n}<br \/>\n}<br \/>\n?&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; to interface to the great ImageMagick image manipulation software.<\/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='#d64374' onclick='var dv=document.getElementById(\"d64374\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/class\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d64374' 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='#d66226' onclick='var dv=document.getElementById(\"d66226\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/postscript\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d66226' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We could spend a lifetime telling you about the functionality of various ImageMagick guises and usages, further to the recent Imagick PHP Class Primer Tutorial. We&#8217;ve decided to live a little separated from ImageMagick, or we just know we would &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/imagemagick-postscript-primer-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,29,37],"tags":[234,2619,590,1658,932,997,1319],"class_list":["post-66226","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-command-line","tag-ghostscript","tag-image","tag-imagemagick","tag-php","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/66226"}],"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=66226"}],"version-history":[{"count":6,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/66226\/revisions"}],"predecessor-version":[{"id":66494,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/66226\/revisions\/66494"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=66226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=66226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=66226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}