{"id":64374,"date":"2024-08-07T03:01:00","date_gmt":"2024-08-06T17:01:00","guid":{"rendered":"https:\/\/65.254.95.247\/ITblog\/?p=64374"},"modified":"2024-08-06T12:06:19","modified_gmt":"2024-08-06T02:06:19","slug":"imagick-php-class-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/imagick-php-class-primer-tutorial\/","title":{"rendered":"Imagick PHP Class Primer Tutorial"},"content":{"rendered":"<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","protected":false},"excerpt":{"rendered":"<p>We&#8217;re talking &#8220;class&#8221; today. Up until now, regarding the great ImageMagick suite of software, and it&#8217;s interactions with PHP, we&#8217;ve &#8230; been using exec style calls of ImageMagick, mainly via it&#8217;s convert command line functionality, via our CentOS web server &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/imagick-php-class-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,28,33,37],"tags":[4855,181,210,1658,4868,707,849,875,932,997,1319],"class_list":["post-64374","post","type-post","status-publish","format-standard","hentry","category-elearning","category-oop","category-software","category-tutorials","tag-almalinux","tag-call","tag-class","tag-imagemagick","tag-imagick","tag-linux","tag-object","tag-oop","tag-php","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/64374"}],"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=64374"}],"version-history":[{"count":5,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/64374\/revisions"}],"predecessor-version":[{"id":64380,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/64374\/revisions\/64380"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=64374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=64374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=64374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}