Exemple #1
2
function MyImageBlur($im, $pct) {
	// w00t. my very own blur function
	// in GD2, there's a gaussian blur function. smarmy bastards. ;-)
	$width = imagesx($im);
	$height = imagesy($im);
	$temp_im = ImageCreate($width, $height);
	$bg = ImageColorAllocate($temp_im, 255, 255, 255);
	// preserves transparency if in orig image
	ImageColorTransparent($temp_im, $bg);
	// fill bg
	ImageFill($temp_im, 0, 0, $bg);
	$distance = 1;
	// emboss:
	ImageCopyMerge($temp_im, $im, 0, 0, $distance, $distance, $width, $height, $pct);
	ImageCopyMerge($im, $temp_im, -$distance, -$distance, 0, 0, $width, $height, $pct);
	ImageFill($temp_im, 0, 0, $bg);
	ImageCopyMerge($temp_im, $im, 0, $distance, $distance, 0, $width, $height, $pct);
	ImageCopyMerge($im, $temp_im, $distance, 0, 0, $distance, $width, $height, $pct);
	// blur:
	ImageCopyMerge($temp_im, $im, 0, $distance, 0, 0, $width, $height, $pct);
	ImageCopyMerge($im, $temp_im, $distance, 0, 0, 0, $width, $height, $pct);
	ImageCopyMerge($temp_im, $im, 0, 0, 0, $distance, $width, $height, $pct);
	ImageCopyMerge($im, $temp_im, 0, 0, $distance, 0, $width, $height, $pct);
	// remove temp image
	ImageDestroy($temp_im);
	return $im;
}
Exemple #2
0
 public function getImage($objUser)
 {
     $img = ImageCreateFromString(base64_decode($this->getFrom('imagedata', 'data')));
     $objPicture = new clsPicture($this->get('picture_id'));
     if (!$objPicture->hasViewed($objUser)) {
         $newImage = clsThumbnail::getNewImage();
         list($newWidth, $newHeight) = clsThumbnail::getNewSize();
         ImageCopyMerge($img, $newImage, $this->get('actual_width') - $newWidth, $this->get('actual_height') - $newHeight, 0, 0, $newWidth, $newHeight, 75);
         ImageDestroy($newImage);
     }
     return $img;
 }
Exemple #3
0
function morph($im, $sx, $sy, $w, $h)
{
    $morphx = $h;
    $morphy = mt_rand(3.5, 5.2);
    $mx = $sx;
    $my = $sy;
    $mvalues = array();
    for ($i = 0; $i < $morphx / 2; $i++) {
        $mvalues[] = $mx - log($i + 1) * $morphy;
        ImageCopyMerge($im, $im, $mvalues[$i], $my + $i, $mx, $my + $i, $w + 20, 1, 0);
    }
    $mvalues = array_reverse($mvalues);
    $mvcount = count($mvalues);
    for ($i = 0; $i < $mvcount; $i++) {
        ImageCopyMerge($im, $im, $mvalues[$i], $my + $i + $mvcount, $mx, $my + $i + $mvcount, $w + 20, 1, 0);
    }
}
Exemple #4
0
function myImageBlur($im)
{
    $width = imagesx($im);
    $height = imagesy($im);
    $temp_im = ImageCreateTrueColor($width, $height);
    $bg = ImageColorAllocate($temp_im, 150, 150, 150);
    // preserves transparency if in orig image
    ImageColorTransparent($temp_im, $bg);
    // fill bg
    ImageFill($temp_im, 0, 0, $bg);
    $distance = 1;
    // blur by merging with itself at different x/y offsets:
    ImageCopyMerge($temp_im, $im, 0, 0, 0, $distance, $width, $height - $distance, 70);
    ImageCopyMerge($im, $temp_im, 0, 0, $distance, 0, $width - $distance, $height, 70);
    ImageCopyMerge($temp_im, $im, 0, $distance, 0, 0, $width, $height, 70);
    ImageCopyMerge($im, $temp_im, $distance, 0, 0, 0, $width, $height, 70);
    // remove temp image
    ImageDestroy($temp_im);
    return $im;
}
 function Blur(&$imgResource, $iRadius = 1)
 {
     $iRadius = round(max(0, min($iRadius, 50)) * 2);
     if (!$iRadius) {
         return false;
     }
     $w = ImageSX($imgResource);
     $h = ImageSY($imgResource);
     if ($imgBlur = ImageCreateTrueColor($w, $h)) {
         // Gaussian blur matrix:
         //	1	2	1
         //	2	4	2
         //	1	2	1
         // Move copies of the image around one pixel at the time and merge them with weight
         // according to the matrix. The same matrix is simply repeated for higher radii.
         for ($i = 0; $i < $iRadius; $i++) {
             ImageCopy($imgBlur, $imgResource, 0, 0, 1, 1, $w - 1, $h - 1);
             // up left
             ImageCopyMerge($imgBlur, $imgResource, 1, 1, 0, 0, $w, $h, 50.0);
             // down right
             ImageCopyMerge($imgBlur, $imgResource, 0, 1, 1, 0, $w - 1, $h, 33.33333);
             // down left
             ImageCopyMerge($imgBlur, $imgResource, 1, 0, 0, 1, $w, $h - 1, 25.0);
             // up right
             ImageCopyMerge($imgBlur, $imgResource, 0, 0, 1, 0, $w - 1, $h, 33.33333);
             // left
             ImageCopyMerge($imgBlur, $imgResource, 1, 0, 0, 0, $w, $h, 25.0);
             // right
             ImageCopyMerge($imgBlur, $imgResource, 0, 0, 0, 1, $w, $h - 1, 20.0);
             // up
             ImageCopyMerge($imgBlur, $imgResource, 0, 1, 0, 0, $w, $h, 16.666667);
             // down
             ImageCopyMerge($imgBlur, $imgResource, 0, 0, 0, 0, $w, $h, 50.0);
             // center
             ImageCopy($imgResource, $imgBlur, 0, 0, 0, 0, $w, $h);
         }
         return true;
     }
     return false;
 }
 /**
  * apply light effect for the given gd resource except the selected area <br>
  * or part of given gd resource <br/>
  * <b>Important:</b>
  * This method require PHP to be compiled with the bundled version of the GD library.
  * @param resource $virtual_image gd resource
  * @param integer $x x coordinate to start point
  * @param integer $y y coordinate to start point
  * @param integer $width  width
  * @param integer $height height
  * @param boolean $invert if true apply effect for selected area if false all except the selected area
  * @return boolean true on success false otherwise
  */
 private static function _light_part($virtual_image, $x, $y, $width, $height, $invert)
 {
     self::activateAlphaChannel($virtual_image);
     $copy = self::gdClone($virtual_image);
     if ($copy) {
         self::activateAlphaChannel($copy);
         if ($invert == true) {
             $light_image = self::light($copy);
             if ($light_image) {
                 return @ImageCopyMerge($virtual_image, $copy, $x, $y, $x, $y, $width, $height, 100);
             }
         }
         if ($invert == false) {
             $light_image = self::light($virtual_image);
             if ($light_image) {
                 return @ImageCopyMerge($virtual_image, $copy, $x, $y, $x, $y, $width, $height, 100);
             }
         }
     }
     return false;
 }
Exemple #7
0
}
#-------------------------------------------------------------------------------
$Icon = IO_Read($Path);
if (Is_Error($Icon)) {
    return ERROR | @Trigger_Error(500);
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
if ($Messages) {
    #-------------------------------------------------------------------------------
    # создаём маленькую картинку с числом
    $ImageSmall = @ImageCreate(9, 9);
    $BgColor = ImageColorAllocate($ImageSmall, 255, 0, 0);
    // красная
    $TextColor = ImageColorAllocate($ImageSmall, 0, 0, 0);
    // чёрный
    ImageString($ImageSmall, 3, 1, -2, $Messages, $TextColor);
    #-------------------------------------------------------------------------------
    # готовим большую картинку
    $ImageBig = @ImageCreateFromPNG($Path);
    #-------------------------------------------------------------------------------
    # накладываем маленькую картинку на большую
    ImageCopyMerge($ImageBig, $ImageSmall, 9, 7, 0, 0, 9, 9, 100);
    $Icon = ImagePNG($ImageBig);
    #-------------------------------------------------------------------------------
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
return $Icon;
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
<?php

$image = ImageCreateFromPNG('/path/to/image.png');
$stamp = ImageCreateFromPNG('/path/to/stamp.png');
$margin = ['right' => 10, 'bottom' => 10];
// offset from the edge
$opacity = 50;
// between 0 and 100%
ImageCopyMerge($image, $stamp, imagesx($image) - imagesx($stamp) - $margin['right'], imagesy($image) - imagesy($stamp) - $margin['bottom'], 0, 0, imagesx($stamp), imagesy($stamp), $opacity);
Exemple #9
0
 public function Blur(&$gdimg, $radius = 0.5)
 {
     // Taken from Torstein Hønsi's phpUnsharpMask (see phpthumb.unsharp.php)
     $radius = round(max(0, min($radius, 50)) * 2);
     if (!$radius) {
         return false;
     }
     $w = ImageSX($gdimg);
     $h = ImageSY($gdimg);
     if ($imgBlur = ImageCreateTrueColor($w, $h)) {
         // Gaussian blur matrix:
         //	1	2	1
         //	2	4	2
         //	1	2	1
         // Move copies of the image around one pixel at the time and merge them with weight
         // according to the matrix. The same matrix is simply repeated for higher radii.
         for ($i = 0; $i < $radius; $i++) {
             ImageCopy($imgBlur, $gdimg, 0, 0, 1, 1, $w - 1, $h - 1);
             // up left
             ImageCopyMerge($imgBlur, $gdimg, 1, 1, 0, 0, $w, $h, 50.0);
             // down right
             ImageCopyMerge($imgBlur, $gdimg, 0, 1, 1, 0, $w - 1, $h, 33.33333);
             // down left
             ImageCopyMerge($imgBlur, $gdimg, 1, 0, 0, 1, $w, $h - 1, 25.0);
             // up right
             ImageCopyMerge($imgBlur, $gdimg, 0, 0, 1, 0, $w - 1, $h, 33.33333);
             // left
             ImageCopyMerge($imgBlur, $gdimg, 1, 0, 0, 0, $w, $h, 25.0);
             // right
             ImageCopyMerge($imgBlur, $gdimg, 0, 0, 0, 1, $w, $h - 1, 20.0);
             // up
             ImageCopyMerge($imgBlur, $gdimg, 0, 1, 0, 0, $w, $h, 16.666667);
             // down
             ImageCopyMerge($imgBlur, $gdimg, 0, 0, 0, 0, $w, $h, 50.0);
             // center
             ImageCopy($gdimg, $imgBlur, 0, 0, 0, 0, $w, $h);
         }
         return true;
     }
     return false;
 }
 function merge($imageObject, $x, $y, $width, $height)
 {
     if ($this->ImageObject === null or $this->ImageObjectRef === null) {
         return false;
     }
     //         ImageAlphaBlending( $this->ImageObject, true );
     imagecolortransparent($imageObject, 0);
     //         ImageCopy( $this->ImageObject, $imageObject, $x, $y, 0, 0, $width, $height );
     ImageCopyMerge($this->ImageObject, $imageObject, $x, $y, 0, 0, $width, $height, 50);
 }
 function make_transparent()
 {
     $info = GetImageSize($this->source_image);
     $width = $info[0];
     $height = $info[1];
     $mime = $info['mime'];
     // What sort of image?
     $type = substr(strrchr($mime, '/'), 1);
     switch ($type) {
         case 'jpeg':
             $image_create_func = 'ImageCreateFromJPEG';
             $image_save_func = 'ImageJPEG';
             $new_image_ext = 'jpg';
             break;
         case 'png':
             $image_create_func = 'ImageCreateFromPNG';
             $image_save_func = 'ImagePNG';
             $new_image_ext = 'png';
             break;
         case 'bmp':
             $image_create_func = 'ImageCreateFromBMP';
             $image_save_func = 'ImageBMP';
             $new_image_ext = 'bmp';
             break;
         case 'gif':
             $image_create_func = 'ImageCreateFromGIF';
             $image_save_func = 'ImageGIF';
             $new_image_ext = 'gif';
             break;
         case 'vnd.wap.wbmp':
             $image_create_func = 'ImageCreateFromWBMP';
             $image_save_func = 'ImageWBMP';
             $new_image_ext = 'bmp';
             break;
         case 'xbm':
             $image_create_func = 'ImageCreateFromXBM';
             $image_save_func = 'ImageXBM';
             $new_image_ext = 'xbm';
             break;
         default:
             $image_create_func = 'ImageCreateFromJPEG';
             $image_save_func = 'ImageJPEG';
             $new_image_ext = 'jpg';
     }
     // Source Image
     $image = $image_create_func($this->source_image);
     $new_image = ImageCreateTruecolor($width, $height);
     // Set a White & Transparent Background Color
     $bg = ImageColorAllocateAlpha($new_image, 255, 255, 255, 127);
     // (PHP 4 >= 4.3.2, PHP 5)
     ImageFill($new_image, 0, 0, $bg);
     // Copy and merge
     ImageCopyMerge($new_image, $image, 0, 0, 0, 0, $width, $height, $this->pct);
     if ($this->save_to_folder) {
         if ($this->new_image_name) {
             $new_name = $this->new_image_name . '.' . $new_image_ext;
         } else {
             $new_name = $this->new_image_name(basename($this->source_image)) . '_transparent' . '.' . $new_image_ext;
         }
         $save_path = $this->save_to_folder . $new_name;
     } else {
         /* Show the image without saving it to a folder */
         header("Content-Type: " . $mime);
         $image_save_func($new_image);
         $save_path = '';
     }
     // Save image
     $process = $image_save_func($new_image, $save_path) or die("There was a problem in saving the new file.");
     return array('result' => $process, 'new_file_path' => $save_path);
 }
Exemple #12
0
 function Blur($im)
 {
     $width = imagesx($im);
     $height = imagesy($im);
     $imgTmp = ImageCreateTrueColor($width, $height);
     $bg = ImageColorAllocate($imgTmp, 255, 255, 255);
     ImageColorTransparent($imgTmp, $bg);
     ImageFill($imgTmp, 0, 0, $bg);
     $d = 1;
     ImageCopyMerge($imgTmp, $im, 0, 0, 0, $d, $width, $height - $d, 70);
     ImageCopyMerge($im, $imgTmp, 0, 0, $d, 0, $width - $d, $height, 70);
     ImageCopyMerge($imgTmp, $im, 0, $d, 0, 0, $width, $height, 70);
     ImageCopyMerge($im, $imgTmp, $d, 0, 0, 0, $width, $height, 70);
     ImageDestroy($imgTmp);
     return $im;
 }
Exemple #13
0
 private function retailler($nouvelle_largeur, $nouvelle_hauteur, $delta_largeur, $delta_hauteur, $reduite = false)
 {
     $ret = false;
     if (!$this->is_null()) {
         $src_r = null;
         if (!strcmp($this->get_ext(), _UPLOAD_EXTENSION_JPG) || !strcmp($this->get_ext(), _UPLOAD_EXTENSION_JPEG)) {
             $src_r = imagecreatefromjpeg($this->get_src());
         } elseif (!strcmp($this->get_ext(), _UPLOAD_EXTENSION_PNG)) {
             $src_r = imagecreatefrompng($this->get_src());
         } elseif (!strcmp($this->get_ext(), _UPLOAD_EXTENSION_GIF)) {
             $src_r = imagecreatefromgif($this->get_src());
         }
         if ($src_r) {
             if ($this->get_ext() == _UPLOAD_EXTENSION_JPG || $this->get_ext() == _UPLOAD_EXTENSION_JPEG) {
                 $dst_r = ImageCreateTrueColor($nouvelle_largeur, $nouvelle_hauteur);
                 if ($dst_r) {
                     imagecopyresampled($dst_r, $src_r, 0, 0, $delta_largeur, $delta_hauteur, $nouvelle_largeur, $nouvelle_hauteur, $this->get_largeur() - 2 * $delta_largeur, $this->get_hauteur() - 2 * $delta_hauteur);
                     $qualite = $reduite ? self::qualite_jpg_reduite : self::qualite_jpg;
                     $ret = imagejpeg($dst_r, $this->get_src(), $qualite);
                     // Mise à jour des nouvelles dimensions
                     $this->largeur = $nouvelle_largeur;
                     $this->hauteur = $nouvelle_hauteur;
                     imagedestroy($dst_r);
                 }
             } elseif ($this->get_ext() == _UPLOAD_EXTENSION_PNG) {
                 $src_alpha = $this->png_has_transparency($this->get_src());
                 $dst_r = ImageCreateTrueColor($nouvelle_largeur, $nouvelle_hauteur);
                 if ($dst_r) {
                     if ($src_alpha) {
                         imagealphablending($dst_r, false);
                         imagesavealpha($dst_r, true);
                     }
                     imagecopyresampled($dst_r, $src_r, 0, 0, $delta_largeur, $delta_hauteur, $nouvelle_largeur, $nouvelle_hauteur, $this->get_largeur() - 2 * $delta_largeur, $this->get_hauteur() - 2 * $delta_hauteur);
                     /* En cas d'image non transparente on reduit à une image avec palette (pb de taille) */
                     if (!$src_alpha) {
                         $tmp = ImageCreateTrueColor($nouvelle_largeur, $nouvelle_hauteur);
                         ImageCopyMerge($tmp, $dst_r, 0, 0, 0, 0, $nouvelle_largeur, $nouvelle_hauteur, 100);
                         ImageTrueColorToPalette($dst_r, false, 8192);
                         ImageColorMatch($tmp, $dst_r);
                         ImageDestroy($tmp);
                     }
                     $qualite = $reduite ? self::qualite_png_reduite : self::qualite_png;
                     $ret = imagepng($dst_r, $this->get_src(), $qualite);
                     // Mise à jour des nouvelles dimensions
                     $this->largeur = $nouvelle_largeur;
                     $this->hauteur = $nouvelle_hauteur;
                     imagedestroy($dst_r);
                 }
             } elseif ($this->get_ext() == _UPLOAD_EXTENSION_GIF) {
                 $dst_r = ImageCreateTrueColor($nouvelle_largeur, $nouvelle_hauteur);
                 if ($dst_r) {
                     imagecopyresampled($dst_r, $src_r, 0, 0, $delta_largeur, $delta_hauteur, $nouvelle_largeur, $nouvelle_hauteur, $this->get_largeur() - 2 * $delta_largeur, $this->get_hauteur() - 2 * $delta_hauteur);
                     $ret = imagegif($dst_r, $this->get_src());
                     // Mise à jour des nouvelles dimensions
                     $this->largeur = $nouvelle_largeur;
                     $this->hauteur = $nouvelle_hauteur;
                     imagedestroy($dst_r);
                 }
             }
             imagedestroy($src_r);
         }
     }
     return $ret;
 }
Exemple #14
0
function wtrmark($sourcefile, $watermarkfile, $text)
{
    $logopath = "/home/www/cb3/img/cb-logo-300.png";
    $logofile_id = imagecreatefrompng($logopath);
    imageAlphaBlending($logofile_id, true);
    imageSaveAlpha($logofile_id, true);
    $fileType = strtolower(substr($sourcefile, strlen($sourcefile) - 3));
    switch ($fileType) {
        case 'gif':
            $sourcefile_id = imagecreatefromgif($sourcefile);
            break;
        case 'png':
            $sourcefile_id = imagecreatefrompng($sourcefile);
            break;
        default:
            $sourcefile_id = imagecreatefromjpeg($sourcefile);
    }
    imageAlphaBlending($sourcefile_id, true);
    imageSaveAlpha($sourcefile_id, true);
    //Get the sizes of both pix
    $sourcefile_width = imageSX($sourcefile_id);
    $sourcefile_height = imageSY($sourcefile_id);
    $logo_width = imageSX($logofile_id);
    $logo_height = imageSY($logofile_id);
    $dest_x_logo = $sourcefile_width - $logo_width - 4;
    $dest_y_logo = $sourcefile_height - $logo_height - 8;
    // if a gif, we have to upsample it to a truecolor image
    if ($fileType == 'gif') {
        // create an empty truecolor container
        $tempimage = imagecreatetruecolor($sourcefile_width, $sourcefile_height);
        // copy the 8-bit gif into the truecolor image
        imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height);
        // copy the source_id int
        $sourcefile_id = $tempimage;
    }
    // create an empty truecolor container
    $tempimage = imagecreatetruecolor($sourcefile_width + 20, $sourcefile_height);
    $bgColor = imagecolorallocate($tempimage, 255, 255, 255);
    imagefill($tempimage, 0, 0, $bgColor);
    // copy the 8-bit gif into the truecolor image
    imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height);
    // copy the source_id int
    $sourcefile_id = $tempimage;
    //text
    $black = ImageColorAllocate($sourcefile_id, 200, 200, 200);
    $white = ImageColorAllocate($sourcefile_id, 255, 255, 255);
    //The canvas's (0,0) position is the upper left corner
    //So this is how far down and to the right the text should start
    $start_x = $sourcefile_width;
    $start_y = $sourcefile_height;
    // write text
    Imagettftext($sourcefile_id, 10, 90, $sourcefile_width + 11, $sourcefile_height, $black, '/home/www/cb3/ales/arial.ttf', $text);
    $opacity_logo = 30;
    ImageCopyMerge($sourcefile_id, $logofile_id, $dest_x_logo, $dest_y_logo, 0, 0, $logo_width, $logo_height, $opacity_logo);
    //Create a jpeg out of the modified picture
    switch ($fileType) {
        // remember we don't need gif any more, so we use only png or jpeg.
        // See the upsaple code immediately above to see how we handle gifs
        case 'png':
            imagepng($sourcefile_id, $sourcefile);
            break;
        default:
            imagejpeg($sourcefile_id, $sourcefile);
    }
    imagedestroy($sourcefile_id);
    imagedestroy($logofile_id);
}
Exemple #15
0
if ($shadow) {
    $box_width = abs($box[2] - $box[0]);
    $box_height = abs($box[5] - $dip);
    $shadow_image = @ImageCreate(abs($box[2] - $box[0]), abs($box[5] - $dip));
    $shadow_background_color = @ImageColorAllocate($shadow_image, $background_rgb['red'], $background_rgb['green'], $background_rgb['blue']);
    $shadow_color = ImageColorAllocate($shadow_image, 0, 0, 0);
    $shadow_copy = ImageCopy($shadow_image, $image, 0, 0, 0, 0, $box_width, $box_height);
    if ($kerning) {
        kern_text($shadow_image, $font_size, 0, ceil($font_size * 0.05) - $box[0], abs($box[5] - $box[3]) - $box[1] + ceil($font_size * 0.05), $shadow_color, $font_file, $text, $kerning);
    } else {
        ImageTTFText($shadow_image, $font_size, 0, ceil($font_size * 0.05) - $box[0], abs($box[5] - $box[3]) - $box[1] + ceil($font_size * 0.05), $shadow_color, $font_file, $text);
    }
    if ($transparent_background) {
        ImageColorTransparent($shadow_image, $shadow_background_color);
    }
    $shadow_merge = ImageCopyMerge($image, $shadow_image, 0, 0, 0, 0, $box_width, $box_height, 15);
    ImageDestroy($shadow_image);
}
kern_text($image, $font_size, 0, -$box[0], abs($box[5] - $box[3]) - $box[1], $font_color, $font_file, $text, $kerning);
/*
ImageTTFText($image,$font_size,0,-$box[0],abs($box[5]-$box[3])-$box[1],
    $font_color,$font_file,$text) ;
*/
// set transparency
if ($transparent_background) {
    ImageColorTransparent($image, $background_color);
}
header('Content-type: ' . $mime_type);
ImagePNG($image);
// save copy of image for cache
if ($cache_images) {
Exemple #16
0
 function mergeColor($color, $opacity)
 {
     $newimage = ImageCreate($this->width, $this->height);
     $r = hexdec(substr($color, 0, 2));
     $g = hexdec(substr($color, 2, 2));
     $b = hexdec(substr($color, 4, 2));
     $mergecolor = ImageColorAllocate($newimage, $r, $g, $b);
     ImageCopyMerge($this->handle, $newimage, 0, 0, 0, 0, $this->width, $this->height, $opacity);
     return $this->createUnique($this->handle);
 }
 /**
  * ImageConverter::doMerge()
  *
  * Merge the image with a stamp
  *
  * @param string $sStamp: the stamp image
  * @param string $sAlign: the horizontal alignment of the stamp (give in percentage or as top, center, bottom)
  * @param string $sValign: the vertial alignment of the stamp (give in percentage or as top, middle, bottom)
  * @param array $aTransparant: array of rgb color value which should be transparant
  * @return void
  * @access public
  * @author Teye Heimans
  */
 function doMerge($sStamp, $sAlign, $sValign, $aTransparant = null)
 {
     if (file_exists($sStamp)) {
         if (!function_exists('imagecopyresampled')) {
             trigger_error('Error, the required function imagecopyresampled does not exists! ' . 'Could not generate new image.', E_USER_WARNING);
             return;
         }
         // Open the current file (get the resource )
         $rImgSrc = $this->_imageCreate($this->_sImage);
         // create the "new" file recourse
         $rImgDest = ImageCreateTrueColor($this->_aSize[0], $this->_aSize[1]);
         // Open the stamp image
         $rImgStamp = $this->_imageCreate($sStamp);
         // Transparant color...
         if (is_array($aTransparant)) {
             $color = ImageColorAllocate($rImgStamp, $aTransparant[0], $aTransparant[1], $aTransparant[2]);
             ImageColorTransparent($rImgStamp, $color);
         }
         // Copy the current file to the new one
         ImageCopy($rImgDest, $rImgSrc, 0, 0, 0, 0, $this->_aSize[0], $this->_aSize[1]);
         ImageDestroy($rImgSrc);
         // get the new position for the stamp
         $x = ImageSX($rImgStamp);
         $y = ImageSY($rImgStamp);
         $posX = $this->_getPos($this->_aSize[0], $x, $sAlign);
         $posY = $this->_getPos($this->_aSize[1], $y, $sValign);
         // copy the stamp to the new image
         ImageCopyMerge($rImgDest, $rImgStamp, $posX, $posY, 0, 0, $x, $y, 100);
         //ImageCopy( $rImgDest, $rImgStamp, $posX, $posY, 0, 0, $x, $y );  # transparant isnt working!
         //ImageCopyResampled( $rImgDest, $rImgStamp, 0, 0, $x, $y, $x, $y ); # transparant isnt working!
         ImageDestroy($rImgStamp);
         // Save the new image
         $this->_saveImage($rImgDest, $this->_sImage, 100);
         ImageDestroy($rImgDest);
     } else {
         trigger_error('Error, stamp file does not exists: ' . $sStamp, E_USER_WARNING);
     }
 }
 function RoundedImageCorners()
 {
     if (phpthumb_functions::gd_version() < 2) {
         return false;
     }
     if (!empty($this->brx) && !empty($this->bry) && $this->bw == 0) {
         $gdimg_cornermask = $this->ImageCreateFunction($this->thumbnail_width, $this->thumbnail_height);
         $background_color_cornermask = phpthumb_functions::ImageHexColorAllocate($gdimg_cornermask, $this->config_background_hexcolor);
         $border_color_cornermask = phpthumb_functions::ImageHexColorAllocate($gdimg_cornermask, $this->config_border_hexcolor);
         // Top Left
         ImageArc($gdimg_cornermask, $this->brx - 1, $this->bry - 1, $this->brx * 2, $this->bry * 2, 180, 270, $background_color_cornermask);
         ImageFillToBorder($gdimg_cornermask, 0, 0, $background_color_cornermask, $background_color_cornermask);
         // Top Right
         ImageArc($gdimg_cornermask, $this->thumbnail_width - $this->brx, $this->bry - 1, $this->brx * 2, $this->bry * 2, 270, 360, $background_color_cornermask);
         ImageFillToBorder($gdimg_cornermask, $this->thumbnail_width, 0, $background_color_cornermask, $background_color_cornermask);
         // Bottom Right
         ImageArc($gdimg_cornermask, $this->thumbnail_width - $this->brx, $this->thumbnail_height - $this->bry, $this->brx * 2, $this->bry * 2, 0, 90, $background_color_cornermask);
         ImageFillToBorder($gdimg_cornermask, $this->thumbnail_width, $this->thumbnail_height, $background_color_cornermask, $background_color_cornermask);
         // Bottom Left
         ImageArc($gdimg_cornermask, $this->brx - 1, $this->thumbnail_height - $this->bry, $this->brx * 2, $this->bry * 2, 90, 180, $background_color_cornermask);
         ImageFillToBorder($gdimg_cornermask, 0, $this->thumbnail_height, $background_color_cornermask, $background_color_cornermask);
         $transparent_color_cornermask = ImageColorTransparent($gdimg_cornermask, ImageColorAt($gdimg_cornermask, round($this->thumbnail_width / 2), round($this->thumbnail_height / 2)));
         ImageArc($gdimg_cornermask, $this->brx, $this->bry, $this->brx * 2, $this->bry * 2, 180, 270, $transparent_color_cornermask);
         ImageArc($gdimg_cornermask, $this->thumbnail_width - $this->brx, $this->bry, $this->brx * 2, $this->bry * 2, 270, 360, $transparent_color_cornermask);
         ImageArc($gdimg_cornermask, $this->thumbnail_width - $this->brx, $this->thumbnail_height - $this->bry, $this->brx * 2, $this->bry * 2, 0, 90, $transparent_color_cornermask);
         ImageArc($gdimg_cornermask, $this->brx, $this->thumbnail_height - $this->bry, $this->brx * 2, $this->bry * 2, 90, 180, $transparent_color_cornermask);
         ImageCopyMerge($this->gdimg_output, $gdimg_cornermask, 0, 0, 0, 0, $this->thumbnail_width, $this->thumbnail_height, 100);
         // Make rounded corners transparent (optional)
         if (!empty($this->bct)) {
             if ($this->bct == 256) {
                 ImageTrueColorToPalette($this->gdimg_output, true, 256);
             }
             ImageColorTransparent($this->gdimg_output, ImageColorAt($this->gdimg_output, 0, 0));
         }
     }
     return true;
 }
Exemple #19
0
 function create_watermark($file)
 {
     //文件不存在则返回
     if (!file_exists($this->watermark_file) || !file_exists($file)) {
         return;
     }
     if (!function_exists('getImageSize')) {
         return;
     }
     //检查GD支持的文件类型
     $gd_allow_types = array();
     if (function_exists('ImageCreateFromGIF')) {
         $gd_allow_types['image/gif'] = 'ImageCreateFromGIF';
     }
     if (function_exists('ImageCreateFromPNG')) {
         $gd_allow_types['image/png'] = 'ImageCreateFromPNG';
     }
     if (function_exists('ImageCreateFromJPEG')) {
         $gd_allow_types['image/jpeg'] = 'ImageCreateFromJPEG';
     }
     //获取文件信息
     $fileinfo = getImageSize($file);
     $wminfo = getImageSize($this->watermark_file);
     if ($fileinfo[0] < $wminfo[0] || $fileinfo[1] < $wminfo[1]) {
         return;
     }
     if (array_key_exists($fileinfo['mime'], $gd_allow_types)) {
         if (array_key_exists($wminfo['mime'], $gd_allow_types)) {
             // 从文件创建图像
             $temp = $gd_allow_types[$fileinfo['mime']]($file);
             $temp_wm = $gd_allow_types[$wminfo['mime']]($this->watermark_file);
             // 水印位置
             switch ($this->watermark_pos) {
                 case 1:
                     //顶部居左
                     $dst_x = 0;
                     $dst_y = 0;
                     break;
                 case 2:
                     //顶部居中
                     $dst_x = ($fileinfo[0] - $wminfo[0]) / 2;
                     $dst_y = 0;
                     break;
                 case 3:
                     //顶部居右
                     $dst_x = $fileinfo[0];
                     $dst_y = 0;
                     break;
                 case 4:
                     //底部居左
                     $dst_x = 0;
                     $dst_y = $fileinfo[1];
                     break;
                 case 5:
                     //底部居中
                     $dst_x = ($fileinfo[0] - $wminfo[0]) / 2;
                     $dst_y = $fileinfo[1];
                     break;
                 case 6:
                     //底部居右
                     $dst_x = $fileinfo[0] - $wminfo[0];
                     $dst_y = $fileinfo[1] - $wminfo[1];
                     break;
                 default:
                     //随机
                     $dst_x = mt_rand(0, $fileinfo[0] - $wminfo[0]);
                     $dst_y = mt_rand(0, $fileinfo[1] - $wminfo[1]);
             }
             if (function_exists('ImageAlphaBlending')) {
                 ImageAlphaBlending($temp_wm, True);
             }
             // 设定图像的混色模式
             if (function_exists('ImageSaveAlpha')) {
                 ImageSaveAlpha($temp_wm, True);
             }
             // 保存完整的 alpha 通道信息
             //为图像添加水印
             if (function_exists('imageCopyMerge')) {
                 ImageCopyMerge($temp, $temp_wm, $dst_x, $dst_y, 0, 0, $wminfo[0], $wminfo[1], $this->watermark_trans);
             } else {
                 ImageCopyMerge($temp, $temp_wm, $dst_x, $dst_y, 0, 0, $wminfo[0], $wminfo[1]);
             }
             // 保存图片
             switch ($fileinfo['mime']) {
                 case 'image/jpeg':
                     @imageJPEG($temp, $file);
                     break;
                 case 'image/png':
                     @imagePNG($temp, $file);
                     break;
                 case 'image/gif':
                     @imageGIF($temp, $file);
                     break;
             }
             // 销毁零时图像
             @imageDestroy($temp);
             @imageDestroy($temp_wm);
         }
     }
 }
 static function applyUnsharpMask(&$img, $amount, $radius, $threshold)
 {
     // $img is an image that is already created within php using
     // imgcreatetruecolor. No url! $img must be a truecolor image.
     // Attempt to calibrate the parameters to Photoshop:
     $amount = min($amount, 500) * 0.016;
     $radius = abs(round(min(50, $radius) * 2));
     // Only integers make sense.
     $threshold = min(255, $threshold);
     if ($radius == 0) {
         return true;
     }
     $w = ImageSX($img);
     $h = ImageSY($img);
     $imgCanvas = ImageCreateTrueColor($w, $h);
     $imgBlur = ImageCreateTrueColor($w, $h);
     // Gaussian blur matrix:
     //
     //    1    2    1
     //    2    4    2
     //    1    2    1
     //
     //////////////////////////////////////////////////
     if (function_exists('imageconvolution')) {
         // PHP >= 5.1
         $matrix = array(array(1, 2, 1), array(2, 4, 2), array(1, 2, 1));
         ImageCopy($imgBlur, $img, 0, 0, 0, 0, $w, $h);
         ImageConvolution($imgBlur, $matrix, 16, 0);
     } else {
         // Move copies of the image around one pixel at the time and merge them with weight
         // according to the matrix. The same matrix is simply repeated for higher radii.
         for ($i = 0; $i < $radius; $i++) {
             ImageCopy($imgBlur, $img, 0, 0, 1, 0, $w - 1, $h);
             // left
             ImageCopyMerge($imgBlur, $img, 1, 0, 0, 0, $w, $h, 50);
             // right
             ImageCopyMerge($imgBlur, $img, 0, 0, 0, 0, $w, $h, 50);
             // center
             ImageCopy($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 33.33333);
             // up
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 25);
             // down
         }
     }
     if ($threshold > 0) {
         // Calculate the difference between the blurred pixels and the original
         // and set the pixels
         for ($x = 0; $x < $w - 1; $x++) {
             // each row
             for ($y = 0; $y < $h; $y++) {
                 // each pixel
                 $rgbOrig = ImageColorAt($img, $x, $y);
                 $rOrig = $rgbOrig >> 16 & 0xff;
                 $gOrig = $rgbOrig >> 8 & 0xff;
                 $bOrig = $rgbOrig & 0xff;
                 $rgbBlur = ImageColorAt($imgBlur, $x, $y);
                 $rBlur = $rgbBlur >> 16 & 0xff;
                 $gBlur = $rgbBlur >> 8 & 0xff;
                 $bBlur = $rgbBlur & 0xff;
                 // When the masked pixels differ less from the original
                 // than the threshold specifies, they are set to their original value.
                 $rNew = abs($rOrig - $rBlur) >= $threshold ? max(0, min(255, $amount * ($rOrig - $rBlur) + $rOrig)) : $rOrig;
                 $gNew = abs($gOrig - $gBlur) >= $threshold ? max(0, min(255, $amount * ($gOrig - $gBlur) + $gOrig)) : $gOrig;
                 $bNew = abs($bOrig - $bBlur) >= $threshold ? max(0, min(255, $amount * ($bOrig - $bBlur) + $bOrig)) : $bOrig;
                 if ($rOrig != $rNew || $gOrig != $gNew || $bOrig != $bNew) {
                     $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);
                     ImageSetPixel($img, $x, $y, $pixCol);
                 }
             }
         }
     } else {
         for ($x = 0; $x < $w; $x++) {
             // each row
             for ($y = 0; $y < $h; $y++) {
                 // each pixel
                 $rgbOrig = ImageColorAt($img, $x, $y);
                 $rOrig = $rgbOrig >> 16 & 0xff;
                 $gOrig = $rgbOrig >> 8 & 0xff;
                 $bOrig = $rgbOrig & 0xff;
                 $rgbBlur = ImageColorAt($imgBlur, $x, $y);
                 $rBlur = $rgbBlur >> 16 & 0xff;
                 $gBlur = $rgbBlur >> 8 & 0xff;
                 $bBlur = $rgbBlur & 0xff;
                 $rNew = min(255, max(0, $amount * ($rOrig - $rBlur) + $rOrig));
                 $gNew = min(255, max(0, $amount * ($gOrig - $gBlur) + $gOrig));
                 $bNew = min(255, max(0, $amount * ($bOrig - $bBlur) + $bOrig));
                 $rgbNew = ($rNew << 16) + ($gNew << 8) + $bNew;
                 ImageSetPixel($img, $x, $y, $rgbNew);
             }
         }
     }
     ImageDestroy($imgCanvas);
     ImageDestroy($imgBlur);
     return true;
 }
Exemple #21
0
function UnsharpMask($img, $amount = 100, $radius = 0.5, $threshold = 3)
{
    $amount = min($amount, 500);
    $amount = $amount * 0.016;
    if ($amount == 0) {
        return true;
    }
    $radius = min($radius, 50);
    $radius = $radius * 2;
    $threshold = min($threshold, 255);
    $radius = abs(round($radius));
    if ($radius == 0) {
        return true;
    }
    $w = ImageSX($img);
    $h = ImageSY($img);
    $imgCanvas = ImageCreateTrueColor($w, $h);
    $imgCanvas2 = ImageCreateTrueColor($w, $h);
    $imgBlur = ImageCreateTrueColor($w, $h);
    $imgBlur2 = ImageCreateTrueColor($w, $h);
    ImageCopy($imgCanvas, $img, 0, 0, 0, 0, $w, $h);
    ImageCopy($imgCanvas2, $img, 0, 0, 0, 0, $w, $h);
    for ($i = 0; $i < $radius; $i++) {
        ImageCopy($imgBlur, $imgCanvas, 0, 0, 1, 1, $w - 1, $h - 1);
        ImageCopyMerge($imgBlur, $imgCanvas, 1, 1, 0, 0, $w, $h, 50);
        ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 1, 0, $w - 1, $h, 33.33333);
        ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 1, $w, $h - 1, 25);
        ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 1, 0, $w - 1, $h, 33.33333);
        ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 0, $w, $h, 25);
        ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 20);
        ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 16.666667);
        // dow
        ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 0, $w, $h, 50);
        ImageCopy($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);
        ImageCopy($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 20);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 16.666667);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
        ImageCopy($imgCanvas2, $imgBlur2, 0, 0, 0, 0, $w, $h);
    }
    for ($x = 0; $x < $w; $x++) {
        for ($y = 0; $y < $h; $y++) {
            $rgbOrig = ImageColorAt($imgCanvas2, $x, $y);
            $rOrig = $rgbOrig >> 16 & 0xff;
            $gOrig = $rgbOrig >> 8 & 0xff;
            $bOrig = $rgbOrig & 0xff;
            $rgbBlur = ImageColorAt($imgCanvas, $x, $y);
            $rBlur = $rgbBlur >> 16 & 0xff;
            $gBlur = $rgbBlur >> 8 & 0xff;
            $bBlur = $rgbBlur & 0xff;
            $rNew = abs($rOrig - $rBlur) >= $threshold ? max(0, min(255, $amount * ($rOrig - $rBlur) + $rOrig)) : $rOrig;
            $gNew = abs($gOrig - $gBlur) >= $threshold ? max(0, min(255, $amount * ($gOrig - $gBlur) + $gOrig)) : $gOrig;
            $bNew = abs($bOrig - $bBlur) >= $threshold ? max(0, min(255, $amount * ($bOrig - $bBlur) + $bOrig)) : $bOrig;
            if ($rOrig != $rNew || $gOrig != $gNew || $bOrig != $bNew) {
                $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);
                ImageSetPixel($img, $x, $y, $pixCol);
            }
        }
    }
    ImageDestroy($imgCanvas);
    ImageDestroy($imgCanvas2);
    ImageDestroy($imgBlur);
    ImageDestroy($imgBlur2);
    return true;
}
function myImageBlur($im)
{
    // w00t. my very own blur function
    // in GD2, there's a gaussian blur function. bunch of bloody show-offs... :-)
    $width = imagesx($im);
    $height = imagesy($im);
    $temp_im = ImageCreateTrueColor($width, $height);
    $bg = ImageColorAllocate($temp_im, 150, 150, 150);
    // preserves transparency if in orig image
    ImageColorTransparent($temp_im, $bg);
    // fill bg
    ImageFill($temp_im, 0, 0, $bg);
    // anything higher than 3 makes it totally unreadable
    // might be useful in a 'real' blur function, though (ie blurring pictures not text)
    $distance = 1;
    // use $distance=30 to have multiple copies of the word. not sure if this is useful.
    // blur by merging with itself at different x/y offsets:
    ImageCopyMerge($temp_im, $im, 0, 0, 0, $distance, $width, $height - $distance, 70);
    ImageCopyMerge($im, $temp_im, 0, 0, $distance, 0, $width - $distance, $height, 70);
    ImageCopyMerge($temp_im, $im, 0, $distance, 0, 0, $width, $height, 70);
    ImageCopyMerge($im, $temp_im, $distance, 0, 0, 0, $width, $height, 70);
    // remove temp image
    ImageDestroy($temp_im);
    return $im;
}
 function BackFill($toFile, $toW, $toH, $isAlpha = false, $red = 255, $green = 255, $blue = 255)
 {
     $toWH = $toW / $toH;
     $srcWH = $this->srcW / $this->srcH;
     if ($toWH <= $srcWH) {
         $ftoW = $toW;
         $ftoH = $ftoW * ($this->srcH / $this->srcW);
     } else {
         $ftoH = $toH;
         $ftoW = $ftoH * ($this->srcW / $this->srcH);
     }
     if (function_exists('imagecreatetruecolor')) {
         @($cImg = ImageCreateTrueColor($toW, $toH));
         if (!$cImg) {
             $cImg = ImageCreate($toW, $toH);
         }
     } else {
         $cImg = ImageCreate($toW, $toH);
     }
     $fromTop = ($toH - $ftoH) / 2;
     //从正中间填充
     $backcolor = imagecolorallocate($cImg, $red, $green, $blue);
     //填充的背景颜色
     if ($isAlpha) {
         //填充透明色
         $backcolor = ImageColorTransparent($cImg, $backcolor);
         $fromTop = $toH - $ftoH;
         //从底部填充
     }
     ImageFilledRectangle($cImg, 0, 0, $toW, $toH, $backcolor);
     if ($this->srcW > $toW || $this->srcH > $toH) {
         $proImg = $this->CreatImage($this->im, $ftoW, $ftoH, 0, 0, 0, 0, $this->srcW, $this->srcH);
         if ($ftoW < $toW) {
             ImageCopy($cImg, $proImg, ($toW - $ftoW) / 2, 0, 0, 0, $ftoW, $ftoH);
         } else {
             if ($ftoH < $toH) {
                 ImageCopy($cImg, $proImg, 0, $fromTop, 0, 0, $ftoW, $ftoH);
             } else {
                 ImageCopy($cImg, $proImg, 0, 0, 0, 0, $ftoW, $ftoH);
             }
         }
     } else {
         ImageCopyMerge($cImg, $this->im, ($toW - $ftoW) / 2, $fromTop, 0, 0, $ftoW, $ftoH, 100);
     }
     return $this->EchoImage($cImg, $toFile);
     ImageDestroy($cImg);
 }
Exemple #24
0
 public static function show_grayscale($filename)
 {
     $img_size = GetImageSize($filename);
     $width = $img_size[0];
     $height = $img_size[1];
     $img = imageCreate($width, $height);
     for ($c = 0; $c < 256; $c++) {
         ImageColorAllocate($img, $c, $c, $c);
     }
     $img2 = ImageCreateFromJpeg($filename);
     ImageCopyMerge($img, $img2, 0, 0, 0, 0, $width, $height, 100);
     imagejpeg($img);
     imagedestroy($img);
 }
 function applyUnsharpMask(&$img, $amount, $radius, $threshold)
 {
     // $img is an image that is already created within php using
     // imgcreatetruecolor. No url! $img must be a truecolor image.
     // Attempt to calibrate the parameters to Photoshop:
     $amount = min($amount, 500);
     $amount = $amount * 0.016;
     if ($amount == 0) {
         return true;
     }
     $radius = min($radius, 50);
     $radius = $radius * 2;
     $threshold = min($threshold, 255);
     $radius = abs(round($radius));
     // Only integers make sense.
     if ($radius == 0) {
         return true;
     }
     $w = ImageSX($img);
     $h = ImageSY($img);
     $imgCanvas = ImageCreateTrueColor($w, $h);
     $imgCanvas2 = ImageCreateTrueColor($w, $h);
     ImageCopy($imgCanvas, $img, 0, 0, 0, 0, $w, $h);
     ImageCopy($imgCanvas2, $img, 0, 0, 0, 0, $w, $h);
     $builtinFilterSucceeded = false;
     if ($radius == 1) {
         if (phpthumb_functions::version_compare_replacement(phpversion(), '5.0.0', '>=') && phpthumb_functions::gd_is_bundled()) {
             if (ImageFilter($imgCanvas, IMG_FILTER_GAUSSIAN_BLUR) && ImageFilter($imgCanvas2, IMG_FILTER_GAUSSIAN_BLUR)) {
                 $builtinFilterSucceeded = true;
             }
         }
     }
     if (!$builtinFilterSucceeded) {
         $imgBlur = ImageCreateTrueColor($w, $h);
         $imgBlur2 = ImageCreateTrueColor($w, $h);
         ///////////////////////////
         //
         // Gaussian blur matrix:
         //	1  2  1
         //	2  4  2
         //	1  2  1
         //
         ///////////////////////////
         // Move copies of the image around one pixel at the time and merge them with weight
         // according to the matrix. The same matrix is simply repeated for higher radii.
         for ($i = 0; $i < $radius; $i++) {
             ImageCopy($imgBlur, $imgCanvas, 0, 0, 1, 1, $w - 1, $h - 1);
             // up left
             ImageCopyMerge($imgBlur, $imgCanvas, 1, 1, 0, 0, $w, $h, 50);
             // down right
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 1, 0, $w - 1, $h, 33.33333);
             // down left
             ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 1, $w, $h - 1, 25);
             // up right
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 1, 0, $w - 1, $h, 33.33333);
             // left
             ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 0, $w, $h, 25);
             // right
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 20);
             // up
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 16.666667);
             // down
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 0, $w, $h, 50);
             // center
             ImageCopy($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);
             // During the loop above the blurred copy darkens, possibly due to a roundoff
             // error. Therefore the sharp picture has to go through the same loop to
             // produce a similar image for comparison. This is not a good thing, as processing
             // time increases heavily.
             ImageCopy($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 20);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 16.666667);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
             ImageCopy($imgCanvas2, $imgBlur2, 0, 0, 0, 0, $w, $h);
         }
         ImageDestroy($imgBlur);
         ImageDestroy($imgBlur2);
     }
     // Calculate the difference between the blurred pixels and the original
     // and set the pixels
     for ($x = 0; $x < $w; $x++) {
         // each row
         for ($y = 0; $y < $h; $y++) {
             // each pixel
             $rgbOrig = ImageColorAt($imgCanvas2, $x, $y);
             $rOrig = $rgbOrig >> 16 & 0xff;
             $gOrig = $rgbOrig >> 8 & 0xff;
             $bOrig = $rgbOrig & 0xff;
             $rgbBlur = ImageColorAt($imgCanvas, $x, $y);
             $rBlur = $rgbBlur >> 16 & 0xff;
             $gBlur = $rgbBlur >> 8 & 0xff;
             $bBlur = $rgbBlur & 0xff;
             // When the masked pixels differ less from the original
             // than the threshold specifies, they are set to their original value.
             $rNew = abs($rOrig - $rBlur) >= $threshold ? max(0, min(255, $amount * ($rOrig - $rBlur) + $rOrig)) : $rOrig;
             $gNew = abs($gOrig - $gBlur) >= $threshold ? max(0, min(255, $amount * ($gOrig - $gBlur) + $gOrig)) : $gOrig;
             $bNew = abs($bOrig - $bBlur) >= $threshold ? max(0, min(255, $amount * ($bOrig - $bBlur) + $bOrig)) : $bOrig;
             if ($rOrig != $rNew || $gOrig != $gNew || $bOrig != $bNew) {
                 $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);
                 ImageSetPixel($img, $x, $y, $pixCol);
             }
         }
     }
     ImageDestroy($imgCanvas);
     ImageDestroy($imgCanvas2);
     return true;
 }
Exemple #26
0
function image_unsharp_mask(&$img)
{
    global $config;
    if (!$config['image_unsharp']) {
        return;
    }
    if (function_exists('imageconvolution')) {
        $matrix = array(array(-1, -1, -1), array(-1, 25, -1), array(-1, -1, -1));
        $divisor = 16;
        $offset = 0;
        imageconvolution($img, $matrix, $divisor, $offset);
    } else {
        $amount = 1000;
        $amount = min($amount, 500);
        $amount = $amount * 0.016;
        if ($amount == 0) {
            return true;
        }
        $w = ImageSX($img);
        $h = ImageSY($img);
        $imgCanvas = ImageCreateTrueColor($w, $h);
        $imgCanvas2 = ImageCreateTrueColor($w, $h);
        $imgBlur = ImageCreateTrueColor($w, $h);
        $imgBlur2 = ImageCreateTrueColor($w, $h);
        ImageCopy($imgCanvas, $img, 0, 0, 0, 0, $w, $h);
        ImageCopy($imgCanvas2, $img, 0, 0, 0, 0, $w, $h);
        ImageCopy($imgBlur, $imgCanvas, 0, 0, 1, 1, $w - 1, $h - 1);
        ImageCopyMerge($imgBlur, $imgCanvas, 1, 1, 0, 0, $w, $h, 50);
        ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 1, 0, $w - 1, $h, 33.33333);
        ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 1, $w, $h - 1, 25);
        ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 1, 0, $w - 1, $h, 33.33333);
        ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 0, $w, $h, 25);
        ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 20);
        ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 16.666667);
        ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 0, $w, $h, 50);
        ImageCopy($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);
        ImageCopy($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 20);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 16.666667);
        ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
        ImageCopy($imgCanvas2, $imgBlur2, 0, 0, 0, 0, $w, $h);
        for ($x = 0; $x < $w; $x++) {
            for ($y = 0; $y < $h; $y++) {
                $rgbOrig = ImageColorAt($imgCanvas2, $x, $y);
                $rOrig = $rgbOrig >> 16 & 0xff;
                $gOrig = $rgbOrig >> 8 & 0xff;
                $bOrig = $rgbOrig & 0xff;
                $rgbBlur = ImageColorAt($imgCanvas, $x, $y);
                $rBlur = $rgbBlur >> 16 & 0xff;
                $gBlur = $rgbBlur >> 8 & 0xff;
                $bBlur = $rgbBlur & 0xff;
                $rNew = max(0, min(255, $amount * ($rOrig - $rBlur) + $rOrig));
                $gNew = max(0, min(255, $amount * ($gOrig - $gBlur) + $gOrig));
                $bNew = max(0, min(255, $amount * ($bOrig - $bBlur) + $bOrig));
                ImageSetPixel($img, $x, $y, ImageColorAllocate($img, $rNew, $gNew, $bNew));
            }
        }
        ImageDestroy($imgCanvas);
        ImageDestroy($imgCanvas2);
        ImageDestroy($imgBlur);
        ImageDestroy($imgBlur2);
    }
}
Exemple #27
0
 /**
  * Applies the effect.
  */
 public function apply()
 {
     $amount = $this->_params['amount'];
     $radius = $this->_params['radius'];
     $threshold = $this->_params['threshold'];
     // Attempt to calibrate the parameters to Photoshop:
     $amount = min($amount, 500);
     $amount = $amount * 0.016;
     if ($amount == 0) {
         return true;
     }
     $radius = min($radius, 50);
     $radius = $radius * 2;
     $threshold = min($threshold, 255);
     $radius = abs(round($radius));
     // Only integers make sense.
     if ($radius == 0) {
         return true;
     }
     $img = $this->_image->_im;
     $w = ImageSX($img);
     $h = ImageSY($img);
     $imgCanvas = ImageCreateTrueColor($w, $h);
     $imgCanvas2 = ImageCreateTrueColor($w, $h);
     $imgBlur = ImageCreateTrueColor($w, $h);
     $imgBlur2 = ImageCreateTrueColor($w, $h);
     ImageCopy($imgCanvas, $img, 0, 0, 0, 0, $w, $h);
     ImageCopy($imgCanvas2, $img, 0, 0, 0, 0, $w, $h);
     // Gaussian blur matrix:
     //
     //  1   2   1
     //  2   4   2
     //  1   2   1
     //
     //////////////////////////////////////////////////
     // Move copies of the image around one pixel at the time and merge them
     // with weight according to the matrix. The same matrix is simply
     // repeated for higher radii.
     for ($i = 0; $i < $radius; $i++) {
         // up left
         ImageCopy($imgBlur, $imgCanvas, 0, 0, 1, 1, $w - 1, $h - 1);
         // down right
         ImageCopyMerge($imgBlur, $imgCanvas, 1, 1, 0, 0, $w, $h, 50);
         // down left
         ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 1, 0, $w - 1, $h, 33.33333);
         // up right
         ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 1, $w, $h - 1, 25);
         // left
         ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 1, 0, $w - 1, $h, 33.33333);
         // right
         ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 0, $w, $h, 25);
         // up
         ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 20);
         // down
         ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 16.666667);
         // center
         ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 0, $w, $h, 50);
         ImageCopy($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);
         // During the loop above the blurred copy darkens, possibly due to
         // a roundoff error. Therefore the sharp picture has to go through
         // the same loop to produce a similar image for comparison. This is
         // not a good thing, as processing time increases heavily.
         ImageCopy($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 20);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 16.666667);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
         ImageCopy($imgCanvas2, $imgBlur2, 0, 0, 0, 0, $w, $h);
     }
     // Calculate the difference between the blurred pixels and the original
     // and set the pixels
     for ($x = 0; $x < $w; $x++) {
         for ($y = 0; $y < $h; $y++) {
             $rgbOrig = ImageColorAt($imgCanvas2, $x, $y);
             $rOrig = $rgbOrig >> 16 & 0xff;
             $gOrig = $rgbOrig >> 8 & 0xff;
             $bOrig = $rgbOrig & 0xff;
             $rgbBlur = ImageColorAt($imgCanvas, $x, $y);
             $rBlur = $rgbBlur >> 16 & 0xff;
             $gBlur = $rgbBlur >> 8 & 0xff;
             $bBlur = $rgbBlur & 0xff;
             // When the masked pixels differ less from the original than
             // the threshold specifies, they are set to their original
             // value.
             $rNew = abs($rOrig - $rBlur) >= $threshold ? max(0, min(255, $amount * ($rOrig - $rBlur) + $rOrig)) : $rOrig;
             $gNew = abs($gOrig - $gBlur) >= $threshold ? max(0, min(255, $amount * ($gOrig - $gBlur) + $gOrig)) : $gOrig;
             $bNew = abs($bOrig - $bBlur) >= $threshold ? max(0, min(255, $amount * ($bOrig - $bBlur) + $bOrig)) : $bOrig;
             if ($rOrig != $rNew || $gOrig != $gNew || $bOrig != $bNew) {
                 $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);
                 ImageSetPixel($img, $x, $y, $pixCol);
             }
         }
     }
     ImageDestroy($imgCanvas);
     ImageDestroy($imgCanvas2);
     ImageDestroy($imgBlur);
     ImageDestroy($imgBlur2);
 }
Exemple #28
0
 function colorDecrease($image, $dither, $ncolors)
 {
     $width = imagesx($image);
     $height = imagesy($image);
     $colors_handle = ImageCreateTrueColor($width, $height);
     ImageCopyMerge($colors_handle, $image, 0, 0, 0, 0, $width, $height, 100);
     ImageTrueColorToPalette($image, $dither, $ncolors);
     ImageColorMatch($colors_handle, $image);
     ImageDestroy($colors_handle);
 }
 function round_edges($edge_rad = 3, $bg_colour = "FFFFFF", $anti_alias = 1)
 {
     $this->er = $edge_rad;
     $this->bgd = $bg_colour;
     $this->aa = min(3, $anti_alias);
     $this->br = $this->hex2rgb(substr($this->bgd, 0, 2));
     $this->bg = $this->hex2rgb(substr($this->bgd, 2, 2));
     $this->bb = $this->hex2rgb(substr($this->bgd, 4, 2));
     $this->dot = @ImageCreate(1, 1);
     $this->dot_base = @ImageColorAllocate($this->dot, $this->br, $this->bg, $this->bb);
     $this->zenitha = @ImageColorClosest($this->t, $this->br, $this->bg, $this->bb);
     for ($this->rr = 0 - $this->er; $this->rr <= $this->er; $this->rr++) {
         $this->ypos = $this->rr < 0 ? $this->rr + $this->er - 1 : $this->r - ($this->er - $this->rr);
         for ($this->cr = 0 - $this->er; $this->cr <= $this->er; $this->cr++) {
             $this->xpos = $this->cr < 0 ? $this->cr + $this->er - 1 : $this->q - ($this->er - $this->cr);
             if ($this->rr !== 0 || $this->cr !== 0) {
                 $this->d_dist = round(sqrt($this->cr * $this->cr + $this->rr * $this->rr));
                 $this->opaci = $this->d_dist < $this->er - $this->aa ? 0 : max(0, 100 - ($this->er - $this->d_dist) * 33);
                 $this->opaci = $this->d_dist > $this->er ? 100 : $this->opaci;
                 @ImageCopyMerge($this->t, $this->dot, $this->xpos, $this->ypos, 0, 0, 1, 1, $this->opaci);
             }
         }
     }
     @imagedestroy($this->dot);
 }
Exemple #30
0
function wtrmark($sourcefile, $watermarkfile)
{
    #
    # $sourcefile = Filename of the picture to be watermarked.
    # $watermarkfile = Filename of the 24-bit PNG watermark file.
    #
    $logopath = "/home/www/cb3/img/cb-logo-300.png";
    $watermarkfile = "/home/www/cb3/img/watermark.png";
    $logofile_id = imagecreatefrompng($logopath);
    $watermarkfile_id = imagecreatefrompng($watermarkfile);
    imageAlphaBlending($watermarkfile_id, true);
    imageSaveAlpha($watermarkfile_id, true);
    imageAlphaBlending($logofile_id, true);
    imageSaveAlpha($logofile_id, true);
    $fileType = strtolower(substr($sourcefile, strlen($sourcefile) - 3));
    switch ($fileType) {
        case 'gif':
            $sourcefile_id = imagecreatefromgif($sourcefile);
            break;
        case 'png':
            $sourcefile_id = imagecreatefrompng($sourcefile);
            break;
        default:
            $sourcefile_id = imagecreatefromjpeg($sourcefile);
    }
    imageAlphaBlending($sourcefile_id, true);
    imageSaveAlpha($sourcefile_id, true);
    //Get the sizes of both pix
    $sourcefile_width = imageSX($sourcefile_id);
    $sourcefile_height = imageSY($sourcefile_id);
    $watermarkfile_width = imageSX($watermarkfile_id);
    $watermarkfile_height = imageSY($watermarkfile_id);
    $logo_width = imageSX($logofile_id);
    $logo_height = imageSY($logofile_id);
    $dest_x = $sourcefile_width / 2 - $watermarkfile_width / 2;
    $dest_y = $sourcefile_height / 2 - $watermarkfile_height / 2;
    $dest_x_logo = $sourcefile_width - $logo_width - 4;
    $dest_y_logo = $sourcefile_height - $logo_height - 4;
    // if a gif, we have to upsample it to a truecolor image
    if ($fileType == 'gif') {
        // create an empty truecolor container
        $tempimage = imagecreatetruecolor($sourcefile_width, $sourcefile_height);
        // copy the 8-bit gif into the truecolor image
        imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height);
        // copy the source_id int
        $sourcefile_id = $tempimage;
    }
    //imagecopy($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0,
    //                   $watermarkfile_width, $watermarkfile_height);
    $opacity = 8;
    $opacity_logo = 50;
    ImageCopyMerge($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0, $watermarkfile_width, $watermarkfile_height, $opacity);
    ImageCopyMerge($sourcefile_id, $logofile_id, $dest_x_logo, $dest_y_logo, 0, 0, $logo_width, $logo_height, $opacity_logo);
    //Create a jpeg out of the modified picture
    switch ($fileType) {
        // remember we don't need gif any more, so we use only png or jpeg.
        // See the upsaple code immediately above to see how we handle gifs
        case 'png':
            //header("Content-type: image/png");
            imagepng($sourcefile_id, $sourcefile);
            break;
        default:
            //header("Content-type: image/jpg");
            imagejpeg($sourcefile_id, $sourcefile);
    }
    imagedestroy($sourcefile_id);
    imagedestroy($watermarkfile_id);
    imagedestroy($logofile_id);
}