/** * enable or disable sending errors to log file * @param boolean $active if true enable sending errors if false disable sending errors * @param boolean $newLogFile if true new log file error will be created if false <br/> * append errors to last created log file */ public static function log($active = true, $newLogFile = true) { if ($newLogFile) { @unlink(LOGGER); } if ($active) { self::$log = true; } }
function resizeImage($filename) { $image = tulipIP::loadImage($this->imgDir . $filename); $dest = $this->imgDir . "thumbs/"; $resized = tulipIP::resize($image, 250, TIP_FIXED); if (tulipIP::getMime($this->imgDir . $filename) == "image/jpeg") { $mime = TIP_JPG; } elseif (tulipIP::getMime($this->imgDir . $filename) == "image/png") { $mime = TIP_PNG; } elseif (tulipIP::getMime($this->imgDir . $filename) == "image/jpg") { $mime = TIP_JPG; } tulipIP::saveImage($dest, $resized, $mime, substr($filename, 0, -4)); imagedestroy($resized); /* $thumbnail = tulipIP::loadImage($this->imgDir..$filename); $copy = tulipIP::gdClone($thumbnail); tulipIP::Gblur($copy, 1); tulipIP::saveImage($dest, $copy, $mime, substr($filename,0,-4)); imagedestroy($copy); */ }
<?php /** * Require The tuliIP class */ require_once '../../tulipIP/tulipIP.class.php'; /** * Load The Image From Source File */ $path = "../../src.jpg"; $image = tulipIP::loadImage($path); /** * Note: flip method return new gd resource and has no effects in the given gd gd resource($image) */ $rotate_left = tulipIP::rotate($image, TIP_ROTATE_LEFT); $rotate_right = tulipIP::rotate($image, TIP_ROTATE_RIGHT); $rotate_upside_down = tulipIP::rotate($image, TIP_ROTATE_UPSIDE_DOWN); /** * Save All created resources */ $dest = "./"; tulipIP::saveImage($dest, $image, TIP_PNG, "original"); tulipIP::saveImage($dest, $rotate_left, TIP_PNG, "rotate-left"); tulipIP::saveImage($dest, $rotate_right, TIP_PNG, "rotate-right"); tulipIP::saveImage($dest, $rotate_upside_down, TIP_PNG, "rotate-upside-down");
* TuliIp positions : * =================== * * TIP_TOP_LEFT * TIP_TOP_CENTER * TIP_TOP_RIGHT * * TIP_LEFT_CENTER * TIP_CENTER * TIP_RIGHT_CENTER * * TIP_BOTTOM_LEFT * TIP_BOTTOM_CENTER * TIP_BOTTOM_RIGHT */ $position = TIP_BOTTOM_RIGHT; // font size(Optional) in range(0,72) where default=20 $fontSize = 20; // font angel(Optional) in range(-360,360) where default=0 $angle = 30; // text margin (Optional) where default=0 $margin = 5; // text color(Optional) where default=black $color = tulipIP::toRGB("#fff"); tulipIP::addText($image, $fontFile, $text, $position, $margin, $color, $fontSize, $angle); // save the result $dest = "./"; header('Content-type:' . TIP_PNG); tulipIP::saveImage(null, $image); tulipIP::saveImage($dest, $image, TIP_JPG, "Watermark");
* Imporatnt : This method require PHP to be compiled with the * =========== bundled version of the GD library. */ $copy = tulipIP::gdClone($image); tulipIP::edge($copy); tulipIP::saveImage($dest, $copy, $mime, 'Edge-filter'); imagedestroy($copy); /* * 9 - Emboss Filter * Imporatnt : This method require PHP to be compiled with the * =========== bundled version of the GD library. */ $copy = tulipIP::gdClone($image); $offset = 1; // color offset in range(1,100) where 1= default $normalization = 127; // color normalization in range (0,360) where 172= default tulipIP::emboss($copy, $offset, $normalization); tulipIP::saveImage($dest, $copy, $mime, 'Emboss-filter'); imagedestroy($copy); /* * 10 - Light Filter * Imporatnt : This method require PHP to be compiled with the * =========== bundled version of the GD library. */ $copy = tulipIP::gdClone($image); tulipIP::light($copy); tulipIP::saveImage($dest, $copy, $mime, 'Light-filter'); imagedestroy($copy); // destroy the original source imagedestroy($image);
$result = tulipIP::gray($img); } else { echo "Unable To Load The Image"; } /** * finally we save imag to directory and show the result in the browser * * Note : pass (null) as dest argument to output the image directly in the browser * ====== * Note : you can change the outputted image format using one of * ====== supported tuliIP formats -> TIP_JPG , TIP_JPEG , TIP_PNG , TIP_GIF * * Important : Do Not Use TIP_JPG as content type when you send Header this * =========== will cause problems in (Safari) and (IE) browsers * use TIP_JPEG instead * * Note : we can change the quality of the outputted image by passing integer in range (0,100) * ====== to saveImage Method where better quality means bigger file(s) size */ $dest = "./"; if ($result) { // output the image directly to the browser header("Content-type:" . TIP_JPEG); tulipIP::saveImage(null, $img); // output the image to the dest directory tulipIP::saveImage($dest, $img, TIP_JPG, "negate-filter", 100); } /** * Destroy the resource */ imagedestroy($img);
<?php /** * Require The tuliIP class */ require_once '../../tulipIP/tulipIP.class.php'; /** * Load The Image From Source File */ $path = "../../src.jpg"; $image = tulipIP::loadImage($path); /** * Note: flip method return new gd resource and has no effects in the given gd gd resource($image) */ $flip_horizental = tulipIP::flip($image, TIP_FLIP_HORIZONTAL); $flip_vertical = tulipIP::flip($image, TIP_FLIP_VERTICAL); $flip_both = tulipIP::flip($image, TIP_FLIP_BOTH); /** * Save All created resources */ $dest = "./"; tulipIP::saveImage($dest, $image, TIP_PNG, "original"); tulipIP::saveImage($dest, $flip_horizental, TIP_PNG, "flib-horizental"); tulipIP::saveImage($dest, $flip_vertical, TIP_PNG, "flip-vertical"); tulipIP::saveImage($dest, $flip_both, TIP_PNG, "flip-both");
* Require The tuliIP class */ require_once '../../tulipIP/tulipIP.class.php'; /** * Load The Image From Source File */ $path = "../../src.jpg"; $image = tulipIP::loadImage($path); //x coordinate to start cropping from // Note you can get the width of $path instead of $image (it's the same) $x = floor(tulipIP::getWidth($image) / 2); //y coordinate to start cropping from $y = 0; // x coordinate where to end the cropping $width = tulipIP::getWidth($path); // y coordinate where to end the cropping $height = tulipIP::getHeight($path); /** * Note: crop method return new gd resource and has no effects in the given gd gd resource($image) * ===== * crop the second half of the image */ $croped_image = tulipIP::crop($image, $x, $y, $x, $height); /** * Save The result */ $dest = "./"; header('Content-type:' . TIP_PNG); tulipIP::saveImage(null, $croped_image); tulipIP::saveImage($dest, $croped_image, TIP_JPG, "croped-image");
* 4- $width -> end x coordinate * 5- $height -> end y coordinate * */ /** * Load The Image From Source File */ $path = "../../src.jpg"; $image = tulipIP::loadImage($path); /** * Appley gray filter for the second half of the gd resource ($image) only */ $dest = "./"; $x = floor(tulipIP::getWidth($image) / 2); $y = 0; $width = tulipIP::getWidth($image); $height = tulipIP::getHeight($image); $copy = tulipIP::gdClone($image); tulipIP::gray_part($copy, $x, $y, $width, $height); tulipIP::saveImage($dest, $copy, TIP_PNG, 'gray_part'); imagedestroy($copy); /** * apply gray filter for the given gd resource except the selected area * where selected area is Square (100*100) in the top left corner of the image */ $copy = tulipIP::gdClone($image); tulipIP::gray_invert($copy, 0, 0, 100, 100); tulipIP::saveImage($dest, $copy, TIP_PNG, 'gray_invertr'); imagedestroy($copy); // destroy the source imagedestroy($image);
imagedestroy($resized); // resize image with the given height(150) and let tulipIP handle the new width (aspect ratio) $resized = tulipIP::resize($image, TIP_FIXED, 150); tulipIP::saveImage($dest, $resized, TIP_PNG, "FIXED-150"); imagedestroy($resized); /** * resize image with the given width(100) and let tulipIP keep original height * You can also do the following * $resized = tulipIP::resize($image, 100,tulipIP::getHeight($image)); */ $resized = tulipIP::resize($image, 100, TIP_CURRENT); tulipIP::saveImage($dest, $resized, TIP_PNG, "100-original"); imagedestroy($resized); /** * resize image with the given height(150) and let tulipIP keep original width * You can also do the following * $resized = tulipIP::resize($image, tulipIP::getWidth($image),150); */ $resized = tulipIP::resize($image, TIP_CURRENT, 150); tulipIP::saveImage($dest, $resized, TIP_PNG, "original-150"); imagedestroy($resized); /** * Note: if the params ($new_width,$new_height) were one of this states : * TIP_FIXED TIP_FIXED * TIP_FIXED TIP_CURRENT * TIP_CURRENT TIP_FIXED * TIP_CURRENT TIP_CURRENT * a copy of given gd resource will be returned with no modifition */ // destroy the source imagedestroy($image);
<?php /** * Require The tuliIP class */ require_once '../../tulipIP/tulipIP.class.php'; /** * Load The Image From Source File */ $path = "../../src.jpg"; $image = tulipIP::loadImage($path); /* * save compressed gd2 casg file so we can restore it after * page refresh or sudden shutdown or .... */ $dest = "./"; tulipIP::saveGD($dest, $image, "cash-file"); // destroy the resource imagedestroy($image); /** * Load The Casg File From dest */ $image = tulipIP::loadGD($dest, "cash-file"); // save the result header('Content-type:' . TIP_PNG); tulipIP::saveImage(null, $image); tulipIP::saveImage($dest, $image, TIP_JPG, "Loaded From Cash File");