Image Conversions via PHP GD Transformations Tutorial
โœ‚๐Ÿƒ๐Ÿพโ€โ™€๏ธ๐Ÿƒ๐Ÿผโ€โ™‚๏ธ
๐Ÿ“–

Image Conversions via PHP GD Transformations Tutorial

Image Conversions via PHP GD Transformations Tutorial

In todayโ€™s work progressing yesterdayโ€™s Image Conversions via PHP GD Command Line Tutorialโ€˜s outcomes โ€ฆ

  • we add into the GD โ€œFilteringโ€ thinking, some โ€œTransformationsโ€ โ€ฆ

    โ€ฆ thinking and functionality โ€ฆ and then โ€ฆ
  • we cater for a โ€œcurlโ€ mode of use โ€ฆ by, up in that top newish block of code โ€œrecreatingโ€ a non-existant $argv[] and $argc to precede any โ€œcommand lineโ€ code that fills in $_POST[] array to join in with โ€œsurfing the webโ€ mode of use โ€ฆ
    <?php


    $beginswitch=false;

    $nextquality=false;

    $argnext=false;

    $results="";

    $curlstr="";

    $iscurl=false;



    if (!isset($argc) && isset($_GET['command'])) { // curl mode of use eg. curl "ht
    tp://localhost:8888/convert_wildcard.php?command=x*.jpg+-q+76+-negate+.jpeg"

    $curlstr="convert_wildcard.php " . str_replace('+',' ',urldecode($_GET['command']));

    $argv=explode(" ", $curlstr);

    $argc=sizeof($argv);

    if (strpos(strtolower($_SERVER['SERVER_NAME']), 'rjmprogramming.com.au') !== false) { $iscurl=true; }

    }




    if (isset($argc)) { // command line mode of use eg. php convert_wildcard.php x*.jpg -q 76 -negate .jpeg

    $results="\n";

    for ($ii=1; $ii<$argc; $ii++) {
    if (trim($argv[$ii]) != '') {
    if ($nextquality) {
    $nextquality=false;
    $_POST['quality']=str_replace('%','',$argv[$ii]);
    } else if (strpos($argv[$ii], '-quality') !== false || strpos($argv[$ii], '-QUALITY') !== false) {
    $beginswitch=true;
    if (strpos($argv[$ii],'=') !== false) {
    $_POST['quality']=str_replace('%','',explode('=', $argv[$ii])[1]);
    } else if (strlen($argv[$ii]) > 8) {

    $_POST['quality']=str_replace('%','',substr($argv[$ii], 8));

    } else {

    $nextquality=true;

    }

    } else if (strpos($argv[$ii], '-q') !== false || strpos($argv[$ii], '-Q') !== false) {

    $beginswitch=true;

    if (strpos($argv[$ii],'=') !== false) {

    $_POST['quality']=str_replace('%','',explode('=', $argv[$ii])[1]);

    } else if (strlen($argv[$ii]) > 2) {

    $_POST['quality']=str_replace('%','',substr($argv[$ii], 2));

    } else {

    $nextquality=true;

    }

    } else if (substr($argv[$ii],0,1) == '-') {

    $beginswitch=true;

    if (strpos($argv[$ii],'=') !== false) {

    $_POST[substr(strtolower(explode('=',$argv[$ii])[0]),1)]='';

    if (sizeof(explode(',',explode('=',$argv[$ii])[1])) == 3) {

    $_POST['args']=explode('=',$argv[$ii])[1];

    } else {

    $_POST['arg1']=explode('=',$argv[$ii])[1];

    }

    } else {

    $_POST[substr(strtolower(explode('=',$argv[$ii])[0]),1)]='';

    $argnext=true;

    }

    } else if (!isset($_POST['ispec'])) {

    $_POST['ispec']=$argv[$ii];

    } else if (!$beginswitch) {

    $_POST['ispec'].="," . $argv[$ii];

    } else if (substr($argv[$ii],0,1) == '.' || strlen($argv[$ii]) == 3) {

    $argnext=false;

    $_POST['outext']=str_replace("..", ".", "." . $argv[$ii]);

    } else if ($argnext) {

    $argnext=false;

    if (sizeof(explode(',',$argv[$ii])) == 3) {

    $_POST['args']=$argv[$ii];

    } else {

    $_POST['arg1']=$argv[$ii];

    }

    }

    }

    }

    }


    ?>
    โ€ฆ and then rearranged (where first blue section just used to be echo ) the last bit of PHP code โ€ฆ
    <?php


    if (isset($argc) && !$iscurl) {

    echo openthese($results);

    } else {

    $htmlis=
    "<!doctyle html>

    <html>

    <head>

    <title>Image Conversions via PHP GD - RJM Programming - October, 2022</title>

    ... etcetera etcetera etcetera ...

    <select id=extsel style=display:none; id=xxxoutext><option value=''>Enter output relative image file extension [.jpeg]</option><option value=.jpeg>.jpeg</option><option value=.jpg>.jpg</option><option value=.png>.png</option><option value=.gif>.gif</option><option value=.JPEG>.JPEG</option><option value=.JPG>.JPG</option><option value=.PNG>.PNG</option><option value=.GIF>.GIF</option></select>

    </body>

    </html>";

    if (!$iscurl) {

    echo $htmlis;

    } else {

    $phtmlis="temphtml.html";

    while (file_exists($phtmlis)) {

    $phtmlis=str_replace(".htm", "0.htm", $phtmlis);

    }

    file_put_contents($phtmlis, $htmlis);

    //exec("cd " . dirname(__FILE__) . " ; open " . $phtmlis); // . " ; rm -f " . $phtmlis);

    echo "Please issue command ...\nopen //www.rjmprogramming.com.au/" . $phtmlis . " \n ... to see results. Omit the open word for Windows. You have up to the next minute to do this. ";

    }

    }



    ?>
    โ€ฆ making a MAMP curl usage such as โ€ฆ


    curl "http://localhost:8888/convert_wildcard.php?command=x*.jpg+-q+76+-negate+.jpeg"


    โ€ฆ open the images in your default desktop image editor, while an RJM Programming incarnation such as โ€ฆ


    curl "http://www.rjmprogramming.com.au/convert_wildcard.php?command=wh*.*g*+-q+76+-negate+.jpeg"


    โ€ฆ will return a string such as โ€ฆ

    Please issue command โ€ฆ
    open http://www.rjmprogramming.com.au/temphtml.html
    โ€ฆ to see results. Omit the open word for Windows. You have up to the next minute to do this.

    โ€ฆ and a quick witted user will copy and paste that open http://www.rjmprogramming.com.au/temphtml.html quickly enough to see a webpage offering image download functionalities

โ€ฆ in thechanged convert_wildcardโšซphpโ€˜s imageโœ‚conversion PHP web application.

Did you know?

With that last โ€œrjmprogramming.com.auโ€ curl scenario it occurs to us, you could optionally do a multiple command (or use type ahead buffer on Windows) like โ€ฆ



curl "http://www.rjmprogramming.com.au/convert_wildcard.php?command=wh*.*g*+-q+76+-negate+.jpeg" ; open http://www.rjmprogramming.com.au/temphtml.html

โ€ฆ for a 99% chance of success without having to worry about the โ€œtoo quickโ€ copying and pasting in less than a minute caper! Blurb output will correct you if temphtml.html is not the go.

Or think procedural scripting where Windows has *.bat batch files and macOS or Linux have shells like sh or bash or csh or ksh (our favourite, called Korn Shell). A scheduled procedural crontab command action part could be a Korn Shell one liner like โ€ฆ



ksh -c 'curl "http://www.rjmprogramming.com.au/convert_wildcard.php?command=wh*.*g*+-q+76+-negate+.jpeg" ; open http://www.rjmprogramming.com.au/temphtml.html'

Then a Korn Shell script weโ€™ll call โ€œdaily.kshโ€ on macOS or Linux could contain โ€ฆ



#!/bin/ksh

curl "http://www.rjmprogramming.com.au/convert_wildcard.php?command=wh*.*g*+-q+76+-negate+.jpeg"

open http://www.rjmprogramming.com.au/temphtml.html

exit

โ€ฆ then, thinking macOS or Linux, make it (perhaps too) executable via โ€ฆ



chmod 777 daily.ksh

โ€ฆ and make happen via โ€ฆ



./daily.ksh



Previous relevant Image Conversions via PHP GD Command Line Tutorial is shown below.

Image Conversions via PHP GD Command Line Tutorial

Image Conversions via PHP GD Command Line Tutorial

In the online woooooorrrrrlllllddd (of surfing the net in a web browser) we hope you see โ€œnothing to see hereโ€ different to yesterdayโ€™s Image Conversions via PHP GD Filters Tutorialโ€˜s exploits with ourโœ‚image conversion PHP web application.

And though this is the boring partner in โ€ฆ

  • must not break previous logics โ€ฆ
  • must work for new functionality

โ€ฆ adage around here trying to keep โ€œbackward compatibilityโ€ as you move forward with a project, it is, often, the most important partner.

As for today, it is more likely our RJM Programming users of thechanged convert_wildcardโšซphp will never access our โ€ฆ

  • new command line mode of use โ€ฆ adding to existant โ€ฆ
  • surfing the net (in a web browser) mode of use โ€ฆ and perhaps into the future a โ€ฆ
  • curl mode of use

โ€ฆ but we think this PHP web application really suits a command line mode of use, given that it so suits a โ€ฆ

  • download to local web server, such as Apache/PHP MAMP environment โ€ฆ and once there โ€ฆ
  • you can control โ€œphpโ€ as a command โ€œverbโ€ on the command line (by adding MAMPโ€™s php executable relevant to your version used, to your operating system PATH environment variable), as convenient, to the point that a command line command such as โ€ฆ


    php convert_wildcard.php x*.jpg -q 76 -negate .jpeg


    โ€ฆ reads as a pretty self-explanatory way to achieve a result string such as โ€ฆ


    New image x.jpeg created โ€ฆ
    New image xcode__fibonacci.jpeg created โ€ฆ
    New image xcode_fibonacci.jpeg created โ€ฆ
    New image xcodefibonacci.jpeg created โ€ฆ
    New image xx.jpeg created โ€ฆ

    โ€ฆ as we got on our MAMP environment here

โ€ฆ paradigm set of conditions, quite like ImageMagick and its command line (โ€œconvertโ€ for macOS and Linux and โ€œmagick.exeโ€ for Windows) image conversion functionality.

The PHP changes were 95% a single block of new code, featuring a โ€œfirst time for usโ€ filling in of $_POST[] array โ€œlinkagesโ€ to โ€œsurfing the netโ€ code in the new โ€œcommand lineโ€ isset($argc) == true mode of use scenario blocks of code, near the top โ€ฆ

<?php


$beginswitch=false;

$nextquality=false;

$argnext=false;

$results="";



if (isset($argc)) { // command line mode of use eg. php convert_wildcard.php x*.jpg -q 76 -negate .jpeg

$results="\n";

for ($ii=1; $ii<$argc; $ii++) {

if (trim($argv[$ii]) != '') {

if ($nextquality) {

$nextquality=false;

$_POST['quality']=str_replace('%','',$argv[$ii]);

} else if (strpos($argv[$ii], '-quality') !== false || strpos($argv[$ii], '-QUALITY') !== false) {

$beginswitch=true;

if (strpos($argv[$ii],'=') !== false) {

$_POST['quality']=str_replace('%','',explode('=', $argv[$ii])[1]);

} else if (strlen($argv[$ii]) > 8) {

$_POST['quality']=str_replace('%','',substr($argv[$ii], 8));

} else {

$nextquality=true;

}

} else if (strpos($argv[$ii], '-q') !== false || strpos($argv[$ii], '-Q') !== false) {

$beginswitch=true;

if (strpos($argv[$ii],'=') !== false) {

$_POST['quality']=str_replace('%','',explode('=', $argv[$ii])[1]);

} else if (strlen($argv[$ii]) > 2) {

$_POST['quality']=str_replace('%','',substr($argv[$ii], 2));

} else {

$nextquality=true;

}

} else if (substr($argv[$ii],0,1) == '-') {

$beginswitch=true;

if (strpos($argv[$ii],'=') !== false) {

$_POST[substr(strtolower(explode('=',$argv[$ii])[0]),1)]='';

if (sizeof(explode(',',explode('=',$argv[$ii])[1])) == 3) {

$_POST['args']=explode('=',$argv[$ii])[1];

} else {

$_POST['arg1']=explode('=',$argv[$ii])[1];

}

} else {

$_POST[substr(strtolower(explode('=',$argv[$ii])[0]),1)]='';

$argnext=true;

}

} else if (!isset($_POST['ispec'])) {

$_POST['ispec']=$argv[$ii];

} else if (!$beginswitch) {

$_POST['ispec'].="," . $argv[$ii];

} else if (substr($argv[$ii],0,1) == '.' || strlen($argv[$ii]) == 3) {

$argnext=false;

$_POST['outext']=str_replace("..", ".", "." . $argv[$ii]);

} else if ($argnext) {

$argnext=false;

if (sizeof(explode(',',$argv[$ii])) == 3) {

$_POST['args']=$argv[$ii];

} else {

$_POST['arg1']=$argv[$ii];

}

}

}

}

}


?>


Previous relevant Image Conversions via PHP GD Filters Tutorial is shown below.

Image Conversions via PHP GD Filters Tutorial

Image Conversions via PHP GD Filters Tutorial

Once in the (PHP) GD-land of yesterdayโ€™s Image Conversions via PHP GD Primer Tutorial, youโ€™d be mad not to facilitate some image filtering which GD is so good at. And so, we have included an optional usage dropdown as per โ€ฆ

โ€ฆ into the mix. We add this select element โ€œdropdownโ€ within the HTML form method=POST action=โ€Hereโ€™s looking at you kidโ€ arrangement. Initially it gets assigned just an ID attribute, with no NAME attribute, which is an ideal arrangement when functionality is optional. And so, if the user chooses a real โ€œfilterโ€ here it gets assigned an appropriate NAME attribute as per the PHPโ€™s Javascript dropdown onchange event logic โ€ฆ

<?php echo โ€


function zoomsame(tvo) {

var tv=tvo.value;

var pa=null;

if (tv.trim() == '' && ('' + tv.length) != '0') { aska=true; }

if (tv.trim() != '') {

tvo.name=tv.trim();

if (aska && askastr.indexOf(';' + tv.trim().toLowerCase() + ';') != -1) {

pa=prompt('Optionally enter argument(s) for ' + tv.trim(), askastr.split(';' + tv.trim().toLowerCase() + ';')[1].split(';')[0]);

if (pa != null) {

if (pa.trim() == '') { pa=null; }

}

}

if (pa != null) {

if (('' + pa.split(',').length) == '3') {

document.getElementById('rotation').name='args';

document.getElementById('rotation').value=pa;

} else {

document.getElementById('rotation').name='arg1';

document.getElementById('rotation').value=pa;

}

} else {

document.getElementById('rotation').name='rotation';

document.getElementById('rotation').value='' + document.getElementById('trot').value;

}

if (tv.trim().toLowerCase() == 'redo') {

redo();

} //alert(11);

//}

}

}


โ€œ; ?>

โ€ฆ turning a โ€œdisplay useful onlyโ€ HTML dropdown element into one whose value is transferred with self-navigation to interest the PHP โ€œrecallโ€ logic โ€ฆ

<?php


function ourimagecreatefromfile($zfilename) {

global $div_img, $ext;

//file_put_contents("qwe.qweaa", $zfilename);

if (isset($_GET['emboss']) || isset($_POST['emboss'])) {

//file_put_contents("qwe.qwe", str_replace(' ','+',urldecode($_GET['emboss'])) . str_replace(' ','+',urldecode($_POST['emboss'])) . $zfilename);

//file_put_contents("qwe.qwex", $_SERVER['HTTP_REFERER']);

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['emboss'])) . str_replace(' ','+',urldecode($_POST['emboss'])) . $zfilename));

$emboss = getpostmaybe('arg1',array([-2, -1, 0], [-1, 1, 1], [0, 1, 2]));

//file_put_contents("qwe.qwexx", $_SERVER['HTTP_REFERER']);

//imageconvolution($jm_php, $emboss, 1, 0);

imagefilter($jm_php, IMG_FILTER_EMBOSS);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

//file_put_contents("qwe.qwez", $_SERVER['HTTP_REFERER']);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

//file_put_contents("qwe.qwey", "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>");

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['edge']) || isset($_POST['edge'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['edge'])) . str_replace(' ','+',urldecode($_POST['edge'])) . $zfilename));

$edge_detect = getpostmaybe('arg1',array([-1, -1, -1], [-1, 8, -1], [-1, -1, -1]));

imageconvolution($jm_php, $edge_detect, 1, 0);

imageconvolution($jm_php, $edge_detect, 1, 255);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['negedge']) || isset($_POST['negedge'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['negedge'])) . str_replace(' ','+',urldecode($_POST['negedge'])) . $zfilename));

$edge_detect = getpostmaybe('arg1',array([-1, -1, -1], [-1, 8, -1], [-1, -1, -1]));

imageconvolution($jm_php, $edge_detect, 1, 0);

//imageconvolution($jm_php, $edge_detect, 1, 255);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['sharpen']) || isset($_POST['sharpen'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['sharpen'])) . str_replace(' ','+',urldecode($_POST['sharpen'])) . $zfilename));

$sharpen = getpostmaybe('arg1',array([0, -1, 0], [-1, 5, -1], [0, -1, 0]));

imageconvolution($jm_php, $sharpen, 1, 0);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['boxblur']) || isset($_POST['boxblur'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['boxblur'])) . str_replace(' ','+',urldecode($_POST['boxblur'])) . $zfilename));

$box_blur = getpostmaybe('arg1',array([1, 1, 1], [1, 1, 1], [1, 1, 1]));

imageconvolution($jm_php, $box_blur, 9, 0);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['grayscale']) || isset($_POST['grayscale'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['grayscale'])) . str_replace(' ','+',urldecode($_POST['grayscale'])) . $zfilename));

imagefilter($jm_php, IMG_FILTER_GRAYSCALE);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['gaussianianblur']) || isset($_POST['gaussianblur'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['gaussianblur'])) . str_replace(' ','+',urldecode($_POST['gaussianblur'])) . $zfilename));

imagefilter($jm_php, IMG_FILTER_GAUSSIAN_BLUR);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['selectiveblur']) || isset($_POST['selectiveblur'])) {



$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['selectiveblur'])) . str_replace(' ','+',urldecode($_POST['selectiveblur'])) . $zfilename));

imagefilter($jm_php, IMG_FILTER_SELECTIVE_BLUR);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;



} else if (isset($_GET['negate']) || isset($_POST['negate'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['negate'])) . str_replace(' ','+',urldecode($_POST['negate'])) . $zfilename));

imagefilter($jm_php, IMG_FILTER_NEGATE);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['colourizered']) || isset($_POST['colourizered']) || isset($_GET['colorizered']) || isset($_POST['colorizered'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['colourizered'])) . str_replace(' ','+',urldecode($_POST['colourizered'])) . $zfilename));

imagefilter($jm_php, IMG_FILTER_COLORIZE, getpostmaybe('arg1',rand(0,255)), 0, 0); //, 100);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['colourizegreen']) || isset($_POST['colourizegreen']) || isset($_GET['colorizegreen']) || isset($_POST['colorizegreen'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['colourizegreen'])) . str_replace(' ','+',urldecode($_POST['colourizegreen'])) . $zfilename));

imagefilter($jm_php, IMG_FILTER_COLORIZE, 0, getpostmaybe('arg1',rand(0,255)), 0); //, 100);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['colourize']) || isset($_POST['colourize']) || isset($_GET['colorize']) || isset($_POST['colorize'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['colourize'])) . str_replace(' ','+',urldecode($_POST['colourize'])) . $zfilename));

imagefilter($jm_php, IMG_FILTER_COLORIZE, getpostmaybe('arg1',rand(0, 255)), getpostmaybe('arg2',rand(0, 255)), getpostmaybe('arg3',rand(0, 255))); //, 100);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['colourizeblue']) || isset($_POST['colourizeblue']) || isset($_GET['colorizeblue']) || isset($_POST['colorizeblue'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['colourizeblue'])) . str_replace(' ','+',urldecode($_POST['colourizeblue'])) . $zfilename));

imagefilter($jm_php, IMG_FILTER_COLORIZE, 0, 0, getpostmaybe('arg1',rand(0,255))); //, 100);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['pixellate']) || isset($_POST['pixellate']) || isset($_GET['pixelate']) || isset($_POST['pixelate'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['pixellate'])) . str_replace(' ','+',urldecode($_POST['pixellate'])) . $zfilename));

imagefilter($jm_php, IMG_FILTER_PIXELATE, getpostmaybe('arg1',rand(1, 9))); // was 3

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['smooth']) || isset($_POST['smooth'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['smooth'])) . str_replace(' ','+',urldecode($_POST['smooth'])) . $zfilename));

imagefilter($jm_php, IMG_FILTER_SMOOTH, getpostmaybe('arg1',rand(5, 35))); // was -1924.124

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['contrast']) || isset($_POST['contrast'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['contrast'])) . str_replace(' ','+',urldecode($_POST['contrast'])) . $zfilename));

imagefilter($jm_php, IMG_FILTER_CONTRAST, getpostmaybe('arg1',rand(-100, 100))); // was -90

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['brightness']) || isset($_POST['brightness'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['brightness'])) . str_replace(' ','+',urldecode($_POST['brightness'])) . $zfilename));

imagefilter($jm_php, IMG_FILTER_BRIGHTNESS, getpostmaybe('arg1',rand(-255, 255))); // was 98

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['sketchy']) || isset($_POST['sketchy']) || isset($_GET['mean_removal']) || isset($_POST['mean_removal']) || isset($_GET['mean-removal']) || isset($_POST['mean-removal'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['sketchy'])) . str_replace(' ','+',urldecode($_POST['sketchy'])) . $zfilename));

imagefilter($jm_php, IMG_FILTER_MEAN_REMOVAL);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['flipvertical']) || isset($_POST['flipvertical'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['flipvertical'])) . str_replace(' ','+',urldecode($_POST['flipvertical'])) . $zfilename));

$jm_php=ourImageFlip($jm_php, '1'); //imageflip($jm_php, IMG_FLIP_VERTICAL);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['fliphorizontal']) || isset($_POST['fliphorizontal'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['fliphorizontal'])) . str_replace(' ','+',urldecode($_POST['fliphorizontal'])) . $zfilename));

$jm_php=ourImageFlip($jm_php, '2'); //imageflip($jm_php, IMG_FLIP_HORIZONTAL);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['flip']) || isset($_POST['flip'])) {

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['flip'])) . str_replace(' ','+',urldecode($_POST['flip'])) . $zfilename));

$jm_php=ourImageFlip($jm_php, '3'); //imageflip($jm_php, IMG_FLIP_BOTH);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

imagejpeg($jm_php, $new_name);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

imagedestroy($jm_php);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

} else if (isset($_GET['rotation']) || isset($_POST['rotation'])) {

//file_put_contents("qwe.qwe1", $zfilename);

$jm_php = imagecreatefromstring(ourfile_get_contents(str_replace(' ','+',urldecode($_GET['flip'])) . str_replace(' ','+',urldecode($_POST['flip'])) . $zfilename));

//file_put_contents("qwe.qwe2", $zfilename);

if (isset($_GET['rotation'])) {

$iim_php=imagerotate($jm_php, floatval(trim(str_replace('+',' ',urldecode($_GET['rotation'])))), 0);

} else if (isset($_POST['rotation'])) {

//file_put_contents("qwe.qwe3", '' . (trim(str_replace('+',' ',urldecode($_POST['rotation'])))));

$iim_php=imagerotate($jm_php, floatval(trim(str_replace('+',' ',urldecode($_POST['rotation'])))), 0);

//file_put_contents("qwe.qwe4", '' . floatval(trim(str_replace('+',' ',urldecode($_POST['rotation'])))));

} else {

$iim_php=imagerotate($jm_php, 0.0, 0);

}

//file_put_contents("qwe.qwe5", $zfilename);

return $jm_php; //$new_name = 'anewimage0.jpg';

$nj=0;

while (file_exists('anewimage' . $nj . '.jpg')) {

$nj++;

$new_name = 'anewimage' . $nj . '.jpg';

}

//file_put_contents("qwe.qwe6", $zfilename);

imagejpeg($iim_php, $new_name);

//file_put_contents("qwe.qwe7", $zfilename);

$qpzm='data:image/jpeg;base64,' . base64_encode(ourfile_get_contents($new_name));

//file_put_contents("qwe.qwe8", $zfilename);

imagedestroy($jm_php);

imagedestroy($iim_php);

//file_put_contents("qwe.qwe9", $zfilename);

unlink($new_name);

if (strpos($_SERVER['HTTP_REFERER'], "/pdfimageplustext.php") !== false) {

echo "<!doctype html><html><body onload=\" if (parent.document.getElementById('slideshow')) { parent.document.getElementById('slideshow').value=parent.undobackup('" . datauriit($qpzm) . "'); parent.forcescale(); } \"></body></html>";

exit;

}

return $qpzm;

}

return imagecreatefromstring(file_get_contents($zfilename)); // 'data:image/' . substr($ext,1) . ";base64," . base64_encode(ourfile_get_contents($zfilename));

}


?>

โ€ฆ PHP code that may be familiar looking to readers of our recent PDF Image and Text Nodes Windows Files Tutorial thread of blog postings. Feel free to try thechanged convert_wildcardโšซphp PHP web application you can also try below.


Previous relevant Image Conversions via PHP GD Primer Tutorial is shown below.

Image Conversions via PHP GD Primer Tutorial

Image Conversions via PHP GD Primer Tutorial

Regular readers at this place will know about our admiration for ImageMagick and its command line (โ€œconvertโ€ for macOS and Linux and โ€œmagick.exeโ€ for Windows) image conversion functionality. Even so, ImageMagick is not capable of โ€ฆ



convert filespec*.*g* *.jpeg

โ€ฆ type of image conversion, in bulk, kind of processing (which Gimp offered with its sadly departed Bimp conversion software in the past). But tailored PHP use of the GD (image manipulation) library, helped out by (good olโ€™) PHP glob, is!

And so, weโ€™ve written a โ€œproof of conceptโ€ converter that you can run at the RJM Programming domain, but weโ€™d recommend for use with an Apache/PHP local web server like MAMP is! (Two in one blog posting is a record โ€ฆ is!)

Get into MAMP, and you might want to download convert_wildcardโšซphp PHP source code to MAMPโ€™s Document Root folder. Else, tryโœ‚it here or below โ€ฆ

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Event-Driven Programming, Operating System, Photography, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *