setStrokeAntialias (true); $this->setStrokeColor ($color); $this->setStrokeWidth ($width); $this->setFillColor ($fill); if ($color == "none" or $color == "transparent") $this->setStrokeAlpha (0); else $this->setStrokeAlpha ($trans); } } function convert_array_xy ($old_array) { $caxy = array (); for ($i = 0; $i < count ($old_array) / 2; $i++) if (isset ($old_array[2 * $i + 1])) $caxy[] = array ('x' => $old_array[2 * $i], 'y' => $old_array[2 * $i + 1]); return $caxy; } function checkdata ($defaults) { global $data; if (!is_array ($defaults)) $defaults = array ($defaults); foreach ($defaults as $i=>$default) if (!isset ($data[$i + 1])) $data[$i + 1] = $default; } function find_channel ($cnst) { switch ($cnst) { case "red" : $cnst = 1; break; case "gray" : $cnst = 2; break; case "cyan" : $cnst = 3; break; case "green" : $cnst = 4; break; case "magenta" : $cnst = 5; break; case "blue" : $cnst = 6; break; case "yellow" : $cnst = 7; break; case "alpha" : $cnst = 8; break; case "opacity" : $cnst = 9; break; case "matte" : $cnst = 10; break; case "black" : $cnst = 11; break; case "index" : $cnst = 12; break; case "all" : $cnst = 13; break; case "default" : $cnst = 14; break; default: $cnst = 0; } return $cnst; } function brightness ($cstring, $amount) { $amount = min (100, $amount); $amount = max (-100, $amount); $cl = new ImagickPixel ($cstring); $carray = $cl->getColor (); if ($amount > 0) $red = round ($carray["r"] + $amount * (255 - $carray["r"]) / 100); else $red = round ($carray["r"] * (1 + $amount / 100)); if ($amount > 0) $green = round ($carray["g"] + $amount * (255 - $carray["g"]) / 100); else $green = round ($carray["g"] * (1 + $amount / 100)); if ($amount > 0) $blue = round ($carray["b"] + $amount * (255 - $carray["b"]) / 100); else $blue = round ($carray["b"] * (1 + $amount / 100)); $clv = "rgb($red,$green,$blue)"; delete_images ($cl); return $clv; } function delete_images ($imagick_array) { if (!is_array ($imagick_array)) $imagick_array = array ($imagick_array); foreach ($imagick_array as $imagick) { $imagick->clear (); $imagick->destroy (); } } function delete_files ($files) { if (!is_array ($files)) $files = array ($files); foreach ($files as $file) unlink ($file); } extract ($_POST); $b = "\r\n"; date_default_timezone_set ("Europe/Berlin"); echo "$b"; echo "$b"; echo "Lee Traynor's InterDraw$b"; echo "$b"; echo "$b"; echo "$b"; echo "$b"; echo "

Lee Traynor's InterDraw

$b"; echo "
$b"; echo "$b"; echo "$b"; echo "$b"; echo "$b"; echo "$b"; if (isset ($dcode)) { $dcode = explode ($b, $dcode); $copies = 0; if ($dcode[0] == "batch") { $orig_dir = getcwd (); chdir ("c:\\Documents and Settings\\Lee Traynor\\My Documents\\My Pictures\\{$dcode[1]}"); $log = fopen ("ID_Log.txt", "a"); fwrite ($log, date ("Y.m.d, H:i:s") . "$b" . trim (implode ($b, $dcode)) . "$b--$b"); fclose ($log); $files = glob ("*.{$dcode[2]}"); $actions = array (); for ($i = 3; $i < count ($dcode) - 1; $i++) array_push ($actions, $dcode[$i]); $actions = implode ($b, $actions); $g_type = $dcode[count ($dcode) - 1]; $dcode = ""; foreach ($files as $item) { $dcode .= "image $item$b$actions$b"; $parts = explode (".", $item); array_pop ($parts); $filestem = implode (".", $parts); $dcode .= "save $filestem.$g_type$b"; } $dcode = explode ($b, $dcode); } foreach ($dcode as $element) { set_time_limit (240); $data = explode (" ", trim ($element)); switch (strtolower ($data[0])) { case "p:": $points = array_shift ($data); break; case "new": if (isset ($im)) { delete_images ($im); if (isset ($filename)) unset ($filename); } $im = new Imagick (); checkdata (array (640, 480, "transparent")); $width = $data[1]; $height = $data[2]; $im->newImage ($width, $height, $data[3]); break; case "save": array_shift ($data); $filename = implode (" ", $data); $parts = explode (".", $filename); $format = array_pop ($parts); $filestem = implode (".", $parts); if (isset ($data[2]) and file_exists ($filename)) { $i = 0; $suffix = "-" . sprintf ("%0$data[2]d", $i) . ".$format"; if (file_exists ("$filestem$suffix")) { do { $i++; $suffix = "-" . sprintf ("%0$data[2]d", $i) . ".$format"; } while (file_exists ("$filestem$suffix")); } $filename = "$filestem$suffix"; } $im->writeImage ($filename); break; case "image": if (isset ($im)) delete_images ($im); array_shift ($data); $file_im = implode (" ", $data); $format = array_pop (explode (".", $file_im)); $im = New Imagick ($file_im); list ($width, $height) = array_values ($im->getImageGeometry ()); break; case "addimage": array_shift ($data); $x = array_shift ($data); $y = array_shift ($data); $file_im = implode (" ", $data); $im_temp = New Imagick ($file_im); $im->compositeImage ($im_temp, imagick::COMPOSITE_DSTOVER, $x, $y); delete_images ($im_temp); break; case "background": $im_temp = new Imagick (); $im_temp->newImage ($width, $height, $data[1]); $im->compositeImage ($im_temp, imagick::COMPOSITE_DSTOVER, 0, 0); delete_images ($im_temp); break; case "line": $draw = new LTImagickDraw (); checkdata (array ("black", 1, 1.0)); $draw->ColorWidthFill ($data[1], $data[2], "none", $data[3]); $draw->setStrokeLineJoin (2); $draw->polyline (convert_array_xy ($points)); break; case "grid": $draw = new LTImagickDraw (); $draw->ColorWidthFill ($data[1], $data[2]); for ($i = 0; $i <= $height / $data[3]; $i++) $draw->line (0, $i * $data[3], $width, $i * $data[3]); for ($i = 0; $i <= $width / $data[3]; $i++) $draw->line ($i * $data[3], 0, $i * $data[3], $height); break; case "ellipse": $draw = new LTImagickDraw (); $draw->ColorWidthFill ($data[1], $data[2], $data[3]); $draw->ellipse ($data[4], $data[5], $data[6], $data[7], 0, 360); break; case "poly": $draw = new LTImagickDraw (); checkdata (array ("black", 1, "none", 1.0)); $draw->ColorWidthFill ($data[1], $data[2], $data[3], $data[4]); $draw->setStrokeLineJoin (2); $draw->polygon (convert_array_xy ($points)); break; case "regpoly": $draw = new LTImagickDraw (); checkdata (array (0, 0, 0, 0, 0, 0, 0, $data[7], 0)); $draw->ColorWidthFill ($data[1], $data[2], $data[3]); $draw->setStrokeLineJoin (2); $rotate = deg2rad ($data[9]); $points = array (); for ($i = 0; $i < $data[4]; $i++) array_push ($points, $data[5] + $data[7] * cos ($rotate + 2 * $i * M_PI / $data[4]), $data[6] + $data[8] * sin ($rotate + 2 * $i * M_PI / $data[4])); $draw->polygon (convert_array_xy ($points)); break; case "text": $draw = new LTImagickDraw (); $draw->ColorWidthFill ($data[1], 1, $data[3]); $draw->setFontSize ($data[2]); $draw->setFont ($data[4]); $draw->setTextAntialias (true); switch ($data[5]) { case "right": $draw->setTextAlignment(Imagick::ALIGN_RIGHT); break; case "left": $draw->setTextAlignment(Imagick::ALIGN_LEFT); break; case "center": $draw->setTextAlignment(Imagick::ALIGN_CENTER); break; } for ($i = 0; $i < 8; $i++) { if ($i == 6) $adjustx = array_shift ($data); elseif ($i == 7) $adjusty = array_shift ($data); else array_shift ($data); } $text = html_entity_decode (implode ("\n", explode ("
", implode (" ", $data))), 0, "UTF-8"); $metrics = $im->queryFontMetrics ($draw, $text); $adjustx = $adjustx * $width / 100; $adjusty = $adjusty / 100 * ($height - $metrics["textHeight"] + $metrics["descender"]) + $metrics["characterHeight"]; $draw->annotation ($adjustx, $adjusty, $text); break; case "scale": switch ($data[1]) { case "w": $width = $data[2]; $height = round ($width * $im->getImageHeight () / $im->getImageWidth ()); break; case "h": $height = $data[2]; $width = round ($height * $im->getImageWidth () / $im->getImageHeight ()); break; case "%": $width = round (($data[2] / 100) * $im->getImageWidth ()); $height = round ($width * $im->getImageHeight () / $im->getImageWidth ()); break; } if (!isset ($data[3])) $data[3] = 1; $im->resizeImage ($width, $height, imagick::FILTER_SINC, $data[3]); break; case "shadow": if (!isset ($data[4])) $data[4] = "ul"; switch ($data[4]) { case "ul": $x = 0; $y = 0; break; case "ur": $x = 4 * $data[3]; $y = 0; break; case "ll": $x = 0; $y = 4 * $data[3]; break; case "lr": $x = 4 * $data[3]; $y = 4 * $data[3]; break; } $shadow = $im->clone (); $shadow->setImageBackgroundColor ($data[1]); $shadow->shadowImage ($data[2], $data[3], 0, 0); $shadow->compositeImage ($im, Imagick::COMPOSITE_OVER, $x, $y); $im = $shadow->clone (); delete_images ($shadow); $width = $im->getImageWidth (); $height = $im->getImageHeight (); break; case "distort": $aspect_ratio = max ($width / $height, $height / $width); $da = $data[2]; $db = $data[3]; switch ($data[1]) { case "barrel": $cnst = imagick::DISTORTION_BARREL; if (isset ($data[4])) $dd = $data[4]; else { if ($db + $da > 0) $dd = 1 - $db * (1 + pow ($aspect_ratio, 2)) - $da * pow (1 + pow ($aspect_ratio, 2), 1.5); else $dd = min (1 - $db * pow ($aspect_ratio, 2) - $da * pow ($aspect_ratio, 3), 1 - $db - $da); } break; } $im->setImageVirtualPixelMethod (imagick::VIRTUALPIXELMETHOD_TRANSPARENT); $im->distortImage ($cnst, array ($da, $db, 0, $dd), true); break; case "oilpaint": checkdata (0); $im->oilPaintImage ($data[1]); break; case "vignette": checkdata (array (0, 0)); $im->vignetteImage ($data[1], $data[2], 0, 0); break; case "despeckle": $im->despeckleImage (); break; case "charcoal": checkdata (array (0, 0)); $im->charcoalImage ($data[1], $data[2]); break; case "emboss": checkdata (array (0, 0)); $im->embossImage ($data[1], $data[2]); break; case "solar": checkdata (0); $im->solarizeImage (pow (2, 12 + $data[1])); break; case "sketch": checkdata (array (0, 0)); $im->sketchImage (0, $data[1], $data[2]); break; case "sigmoid": checkdata (array (0, 0)); $im->sigmoidalContrastImage (true, $data[1], $data[2]); break; case "contrast": checkdata (0); if ($data[1] > 0) for ($i = 0; $i < $data[1]; $i++) $im->contrastImage (true); else for ($i = 0; $i > $data[1]; $i--) $im->contrastImage (false); break; case "sepia": checkdata (0); $im->sepiaToneImage ($data[1]); break; case "equal": $im->equalizeImage (); break; case "normal": checkdata ("all"); $channel = find_channel ($data[1]); $im->normalizeImage ($channel); break; case "negate": checkdata ("all"); $channel = find_channel ($data[1]); $im->negateImage (false, $channel); break; case "poster": checkdata (0); $im->posterizeImage ($data[1], false); break; case "channel": checkdata ("red"); $im->separateImageChannel ($data[1]); break; case "tint": checkdata ("red"); $im->tintImage ($data[1], 1); break; case "gamma": checkdata (array (1.0, "all")); $channel = find_channel ($data[2]); $im->gammaImage ($data[1], $channel); break; case "sector": $draw = new LTImagickDraw (); checkdata (array ("blue", 1, "red", 10, 10, 10, 10, 0, 90, 1)); list (, $l_color, $l_width, $f_color, $cx, $cy, $rw, $rh, $s_deg, $f_deg, $hgt) = $data; $dark_color = brightness ($f_color, -25); $draw->ColorWidthFill ("none", 0, $dark_color); $start = deg2rad ($s_deg); $finish = deg2rad ($f_deg); for ($i = 0; $i < $hgt; $i++) { if ($i == $hgt - 1) $draw->setFillColor ($f_color); $ncy = $cy - $i; $points = array ($cx, $ncy); if ($f_deg - $s_deg > 180) { $draw->ellipse ($cx, $ncy, $rw, $rh, $s_deg, $s_deg + 180); $draw->ellipse ($cx, $ncy, $rw, $rh, $s_deg + 180, $f_deg); array_push ($points, $cx + $rw * cos ($start + M_PI), $ncy + $rh * sin ($start + M_PI)); } else { $draw->ellipse ($cx, $ncy, $rw, $rh, $s_deg, $f_deg); array_push ($points, $cx + $rw * cos ($start), $ncy + $rh * sin ($start)); } array_push ($points, $cx + $rw * cos ($finish), $ncy + $rh * sin ($finish)); $draw->polyline (convert_array_xy ($points)); } $draw->ColorWidthFill ($l_color, $l_width, "transparent"); $draw->ellipse ($cx, $ncy, $rw, $rh, $s_deg, $f_deg); if ($s_deg < 180) $draw->ellipse ($cx, $cy, $rw, $rh, max ($s_deg, 0), min ($f_deg, 180)); elseif ($f_deg > 360) $draw->ellipse ($cx, $cy, $rw, $rh, 0, $f_deg % 360); if ($s_deg > 90 and $s_deg < 270) $draw->line ($cx, $cy, $cx + $rw * cos ($start), $cy + $rh * sin ($start)); if ($f_deg < 90 or ($f_deg > 270 and $f_deg < 450)) $draw->line ($cx, $cy, $cx + $rw * cos ($finish), $cy + $rh * sin ($finish)); $draw->polyline (convert_array_xy (array ($cx + $rw * cos ($finish), $ncy + $rh * sin ($finish), $cx, $ncy, $cx + $rw * cos ($start), $ncy + $rh * sin ($start)))); if (($s_deg < 90 and $f_deg < 90) or ($s_deg > 90 and $f_deg > 90 and $f_deg < 450)) $draw->line ($cx, $cy, $cx, $ncy); if ($s_deg < 270 and $s_deg > 0) $draw->line ($cx + $rw * cos ($start), $ncy + $rh * sin ($start), $cx + $rw * cos ($start), $cy + $rh * sin ($start)); elseif (($s_deg < 0 and $f_deg > 0) or ($s_deg < 360 and $f_deg > 360)) $draw->line ($cx + $rw, $cy, $cx + $rw, $ncy); if ($f_deg < 180 or $f_deg > 270) $draw->line ($cx + $rw * cos ($finish), $ncy + $rh * sin ($finish), $cx + $rw * cos ($finish), $cy + $rh * sin ($finish)); elseif ($s_deg < 180 and $f_deg > 180) $draw->line ($cx - $rw, $cy, $cx - $rw, $ncy); break; case "bluredge": checkdata (array (5, 1, 0)); $im->setImageBackgroundColor ("none"); $im->setImageVirtualPixelMethod (imagick::VIRTUALPIXELMETHOD_TRANSPARENT); $im->setImageMatte (true); $im->blurImage (0, $data[1], imagick::CHANNEL_ALPHA); $im->writeImage ("temp0.png"); exec ("convert temp0.png -background none -virtual-pixel background -channel A -level 0,$data[2]% +channel temp1.png"); delete_images ($im); $im = new Imagick ("temp1.png"); delete_files (array ("temp1.png", "temp0.png")); break; case "rotate": $im->rotateImage ($data[1], $data[2]); list ($width, $height) = array_values ($im->getImageGeometry ()); break; case "reflect-blur": checkdata (array (100, 0, 10)); $im_temp = $im->clone (); $im_temp->flipImage (); $im_temp->writeImage ("sharp.png"); $im_temp->blurImage (0, $data[3]); $im_temp->writeImage ("blur.png"); $mask = new Imagick (); $mask->newPseudoImage ($width, $height, "gradient:black-white"); $mask->writeImage ("mask.png"); exec ("composite blur.png sharp.png mask.png -compose srcover temp.png"); $im_temp = new Imagick ("temp.png"); $mask->newPseudoImage ($width, $height, "gradient:gray{$data[1]}-gray{$data[2]}"); $im_temp->compositeImage ($mask, imagick::COMPOSITE_COPYOPACITY, 0, 0); $im->addImage ($im_temp); delete_images (array ($mask, $im_temp)); delete_files (array ("sharp.png", "blur.png", "temp.png", "mask.png")); $im->resetIterator (); $im = $im->appendImages (true); $height = $height * 2; break; case "atm": checkdata (array (5, 75, 90, 1)); $im_temp = $im->clone (); $im->addImage ($im); $im->modulateImage (100, 0, 100); $im->negateImage (true); $radius = round ($data[1] * ($width + $height) / 200); $im->gaussianBlurImage ($radius, $radius / 3.1); $im->setImageMatte (true); $im->setImageOpacity ($data[2] / 100); $im = $im->flattenImages (); $im->setImageMatte (true); $im->setImageOpacity ($data[3] / 100); for ($i = 0; $i < $data[4]; $i++) $im_temp->compositeImage ($im, imagick::COMPOSITE_SOFTLIGHT, 0, 0); $im = $im_temp->clone (); break; case "chroma": checkdata (array (0, 0)); $diagonal = sqrt (pow ($width, 2) + pow ($height, 2)); $x = $width / $diagonal; $y = $height / $diagonal; $red_ca_x = $x * $data[1]; $red_ca_y = $y * $data[1]; $blue_ca_x = $x * $data[2]; $blue_ca_y = $y * $data[2]; $transform_red = array (0, 0, $red_ca_x, $red_ca_y, 0, $height, $red_ca_x, $height - $red_ca_y, $width, $height, $width - $red_ca_x, $height - $red_ca_y, $width, 0, $width - $red_ca_x, $red_ca_y); $transform_blue = array (0, 0, $blue_ca_x, $blue_ca_y, 0, $height, $blue_ca_x, $height - $blue_ca_y, $width, $height, $width - $blue_ca_x, $height - $blue_ca_y, $width, 0, $width - $blue_ca_x, $blue_ca_y); $red = clone $im; $red->separateImageChannel (imagick::CHANNEL_RED); $red->setImageVirtualPixelMethod (imagick::VIRTUALPIXELMETHOD_EDGE); $red->distortImage (imagick::DISTORTION_PERSPECTIVE, $transform_red, false); $green = clone $im; $green->separateImageChannel (imagick::CHANNEL_GREEN); $red->addImage ($green); $blue = clone $im; $blue->separateImageChannel (imagick::CHANNEL_BLUE); $blue->setImageVirtualPixelMethod (imagick::VIRTUALPIXELMETHOD_EDGE); $blue->distortImage (imagick::DISTORTION_PERSPECTIVE, $transform_blue, false); $red->addImage ($blue); $red->setFirstIterator (); $im = $red->combineImages (imagick::CHANNEL_ALL); delete_images (array ($red, $green, $blue)); break; } if (isset ($draw)) { $im->drawImage ($draw); delete_images ($draw); unset ($draw); } } echo "
Drawing Code:
$b$b"; if (isset ($orig_dir)) chdir ($orig_dir); if (isset ($filename) and in_array ($format, array ("gif", "jpg", "png"))) $im_src = $filename; else { $im->writeImage ("temp.png"); $im_src = "temp.png"; } echo "$b"; delete_images ($im); if (!isset ($filename)) $filename = ""; else $filename .= $b; file_put_contents ("ID_Log.txt", date ("Y.m.d, H:i:s") . "$b" . trim (implode ($b, $dcode)) . "$b$filename--$b", FILE_APPEND); } echo "
$b"; echo "
$b"; ?>