当前位置: 首页>>代码示例>>PHP>>正文


PHP ImageColorAt函数代码示例

本文整理汇总了PHP中ImageColorAt函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageColorAt函数的具体用法?PHP ImageColorAt怎么用?PHP ImageColorAt使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ImageColorAt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: UnsharpMask

function UnsharpMask($img, $amount, $radius, $threshold)
{
    ////////////////////////////////////////////////////////////////////////////////////////////////
    ////
    ////                  p h p U n s h a r p M a s k
    ////
    ////        Unsharp mask algorithm by Torstein H�nsi 2003.
    ////                 thoensi_at_netcom_dot_no.
    ////                   Please leave this notice.
    ////
    ///////////////////////////////////////////////////////////////////////////////////////////////
    if ($amount > 500) {
        $amount = 500;
    }
    $amount = $amount * 0.016;
    if ($radius > 50) {
        $radius = 50;
    }
    $radius = $radius * 2;
    if ($threshold > 255) {
        $threshold = 255;
    }
    $radius = abs(round($radius));
    // Only integers make sense.
    if ($radius == 0) {
        return $img;
        imagedestroy($img);
        break;
    }
    $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);
        // 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);
        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++) {
        // 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;
            $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 $img;
}
开发者ID:stephenjschaefer,项目名称:APlusPhotography,代码行数:95,代码来源:picmgmt.inc.php

示例2: ImageCopyBicubic

/**
 *
 * long description
 * @global object
 * @param object $dst_img
 * @param object $src_img
 * @param int $dst_x
 * @param int $dst_y
 * @param int $src_x
 * @param int $src_y
 * @param int $dst_w
 * @param int $dst_h
 * @param int $src_w
 * @param int $src_h
 * @return bool
 * @todo Finish documenting this function
 */
function ImageCopyBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
    global $CFG;
    if (function_exists('ImageCopyResampled') and $CFG->gdversion >= 2) {
        return ImageCopyResampled($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    }
    $totalcolors = imagecolorstotal($src_img);
    for ($i = 0; $i < $totalcolors; $i++) {
        if ($colors = ImageColorsForIndex($src_img, $i)) {
            ImageColorAllocate($dst_img, $colors['red'], $colors['green'], $colors['blue']);
        }
    }
    $scaleX = ($src_w - 1) / $dst_w;
    $scaleY = ($src_h - 1) / $dst_h;
    $scaleX2 = $scaleX / 2.0;
    $scaleY2 = $scaleY / 2.0;
    for ($j = 0; $j < $dst_h; $j++) {
        $sY = $j * $scaleY;
        for ($i = 0; $i < $dst_w; $i++) {
            $sX = $i * $scaleX;
            $c1 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY + $scaleY2));
            $c2 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY));
            $c3 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY + $scaleY2));
            $c4 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY));
            $red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
            $green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
            $blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
            $color = ImageColorClosest($dst_img, $red, $green, $blue);
            ImageSetPixel($dst_img, $i + $dst_x, $j + $dst_y, $color);
        }
    }
}
开发者ID:vuchannguyen,项目名称:web,代码行数:49,代码来源:gdlib.php

示例3: image_to_text

/**
 * Image to Text
 *
 * Takes a given system image and recreates it with a given string
 * Function accepts arbitrary elements to use for markup
 *
 * @access	public
 * @param	string
 * @param	string
 * @param	string
 * @return	string
 */
function image_to_text($data, $txt, $new_width = NULL, $new_height = NULL, $inline_element = 'span')
{
    $img = imagecreatefromstring($data);
    $width = imagesx($img);
    $height = imagesy($img);
    // add abiilty to resize on the fly
    if ($new_width and $new_height) {
        $new = imagecreatetruecolor($new_width, $new_height);
        imagecopyresampled($new, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
        unset($img);
        $img = $new;
        $width = $new_width;
        $height = $new_height;
        unset($new);
    }
    $counter = 0;
    $output = "";
    for ($i = 0; $i < $height; $i++) {
        for ($j = 0; $j < $width; $j++) {
            $counter = $counter % strlen($txt);
            $cindex = ImageColorAt($img, $j, $i);
            $rgb = ImageColorsForIndex($img, $cindex);
            $hex = rgb2hex(array($rgb['red'], $rgb['green'], $rgb['blue']));
            $output .= '<' . $inline_element . ' style="color:#' . $hex . ';">' . substr($txt, $counter, 1) . '</' . $inline_element . '>';
            $counter++;
        }
        $output .= "<br />";
    }
    return $output;
}
开发者ID:justinhernandez,项目名称:convert,代码行数:42,代码来源:useless_fun.php

示例4: get_hex

 function get_hex($location, $extensions = array('PNG', 'png', 'Png', 'JPG', 'jpg', 'Jpg', 'JPEG', 'jpeg', 'Jpeg', 'GIF', 'gif', 'Gif'), $postvar = "myimage", $getvar = "imgclix")
 {
     if (isset($_GET[$getvar])) {
         foreach ($extensions as $var) {
             if (file_exists($location . str_replace(array("..", ".", $var), '', html_entity_decode($_GET[$getvar])) . "." . $var)) {
                 if (stristr($var, 'png')) {
                     $im = ImageCreateFromPng($location . str_replace(array("..", ".", $var), '', html_entity_decode($_GET[$getvar])) . "." . $var);
                 } elseif (stristr($var, 'gif')) {
                     $im = ImageCreateFromGIF($location . str_replace(array("..", ".", $var), '', html_entity_decode($_GET[$getvar])) . "." . $var);
                 } elseif (stristr($var, 'jpg') || stristr($var, 'jpeg')) {
                     $im = ImageCreateFromJpeg($location . str_replace(array("..", ".", $var), '', html_entity_decode($_GET[$getvar])) . "." . $var);
                 } else {
                     return FALSE;
                 }
                 $rgb = ImageColorAt($im, $_POST[$postvar . '_x'], $_POST[$postvar . '_y']);
                 $rgb = imagecolorsforindex($im, $rgb);
                 $hex = sprintf('#%02X%02X%02X', $rgb['red'], $rgb['green'], $rgb['blue']);
                 break;
             }
         }
     } else {
         return FALSE;
     }
     if (!isset($hex) || $hex == '') {
         return FALSE;
     }
     return $hex;
 }
开发者ID:mndrwd,项目名称:freedomeditor,代码行数:28,代码来源:get_hex.php

示例5: computeII

 protected function computeII($canvas, $image_width, $image_height)
 {
     $ii_w = $image_width + 1;
     $ii_h = $image_height + 1;
     $ii = array();
     $ii2 = array();
     for ($i = 0; $i < $ii_w; $i++) {
         $ii[$i] = 0;
         $ii2[$i] = 0;
     }
     for ($i = 1; $i < $ii_h - 1; $i++) {
         $ii[$i * $ii_w] = 0;
         $ii2[$i * $ii_w] = 0;
         $rowsum = 0;
         $rowsum2 = 0;
         for ($j = 1; $j < $ii_w - 1; $j++) {
             $rgb = ImageColorAt($canvas, $j, $i);
             $red = $rgb >> 16 & 0xff;
             $green = $rgb >> 8 & 0xff;
             $blue = $rgb & 0xff;
             $grey = 0.2989 * $red + 0.587 * $green + 0.114 * $blue >> 0;
             // this is what matlab uses
             $rowsum += $grey;
             $rowsum2 += $grey * $grey;
             $ii_above = ($i - 1) * $ii_w + $j;
             $ii_this = $i * $ii_w + $j;
             $ii[$ii_this] = $ii[$ii_above] + $rowsum;
             $ii2[$ii_this] = $ii2[$ii_above] + $rowsum2;
         }
     }
     return array('ii' => $ii, 'ii2' => $ii2);
 }
开发者ID:npetrovski,项目名称:php5-image,代码行数:32,代码来源:Facedetector.php

示例6: getTextFromImage

function getTextFromImage($file)
{
    $background = imagecreatefromjpeg('background.jpg');
    $image = imagecreatefromstring($file);
    $black = imagecolorallocate($image, 0, 0, 0);
    $min_visible_y = $max_y = imagesy($image);
    $min_visible_x = $max_x = imagesx($image);
    $max_visible_x = $max_visible_y = 0;
    for ($y = 0; $y < $max_y; $y++) {
        for ($x = 0; $x < $max_x; $x++) {
            $pixel = ImageColorAt($image, $x, $y);
            $colors = imagecolorsforindex($image, $pixel);
            $pixel_bg = ImageColorAt($background, $x, $y);
            $colors_bg = imagecolorsforindex($background, $pixel_bg);
            $range = 35;
            if ($colors['red'] + $range > $colors_bg['red'] && $colors['red'] - $range < $colors_bg['red']) {
                imagesetpixel($image, $x, $y, $black);
            } else {
                $min_visible_x = $min_visible_x > $x ? $x : $min_visible_x;
                $max_visible_x = $max_visible_x < $x ? $x : $max_visible_x;
                $min_visible_y = $min_visible_y > $y ? $y : $min_visible_y;
                $max_visible_y = $max_visible_y < $y ? $y : $max_visible_y;
            }
        }
    }
    $image = imagecrop($image, ['x' => $min_visible_x, 'y' => $min_visible_y, 'width' => $max_visible_x, 'height' => $max_visible_y]);
    imagefilter($image, IMG_FILTER_GRAYSCALE);
    $tmpfname = tempnam("/tmp", "OCR");
    imagepng($image, $tmpfname);
    $txt = $ocr->recognize($tmpfname, ['eng'], 3);
    unlink($tmpfname);
    return str_replace("\n", "", $txt);
}
开发者ID:vitormattos,项目名称:ocr-test,代码行数:33,代码来源:index.php

示例7: calcIconImgFeature

 function calcIconImgFeature(&$appImg)
 {
     $features = array();
     $featurePadding = 6;
     //角丸アイコン対策
     $featureWidth = (self::appWidth - $featurePadding) / 3;
     $featureHeight = (self::appHeight - $featurePadding) / 3;
     echo "<br>\n";
     for ($fy = 0; $fy < 3; $fy++) {
         for ($fx = 0; $fx < 3; $fx++) {
             $orgX = $featureWidth * $fx + $featurePadding;
             $orgY = $featureHeight * $fy + $featurePadding;
             $r = $g = $b = 0;
             for ($y = 0; $y < $featureHeight; $y++) {
                 for ($x = 0; $x < $featureWidth; $x++) {
                     $rgb = ImageColorAt($appImg, $orgX + $x, $orgY + $y);
                     $r += $rgb >> 16 & 0xff;
                     $g += $rgb >> 8 & 0xff;
                     $b += $rgb & 0xff;
                 }
             }
             $totalNum = $featureHeight * $featureWidth;
             $rgb = dechex(intval($r / $totalNum)) . dechex(intval($g / $totalNum)) . dechex(intval($b / $totalNum));
             echo "<font color='{$rgb}'>■</font>";
         }
         echo "<br>\n";
     }
     return $features;
 }
开发者ID:kenmaz,项目名称:www.kenmaz.net,代码行数:29,代码来源:resize.php

示例8: convert_to_grayscale

 /**
  * Return the img tag of grayscale image
  * and put the grayscale image under images/grayscale
  * @param $filename
  * @return string
  */
 public function convert_to_grayscale($filename)
 {
     $destination = 'images/grayscale/' . $filename;
     $filename = base_url() . '/images/' . $filename;
     $image = imagecreatefromjpeg($filename);
     $imgw = imagesx($image);
     $imgh = imagesy($image);
     for ($i = 0; $i < $imgw; $i++) {
         for ($j = 0; $j < $imgh; $j++) {
             // get the rgb value for current pixel
             $rgb = ImageColorAt($image, $i, $j);
             // extract each value for r, g, b
             $rr = $rgb >> 16 & 0xff;
             $gg = $rgb >> 8 & 0xff;
             $bb = $rgb & 0xff;
             // get the Value from the RGB value
             $g = round(($rr + $gg + $bb) / 3);
             // grayscale values have r=g=b=g
             $val = imagecolorallocate($image, $g, $g, $g);
             // set the gray value
             imagesetpixel($image, $i, $j, $val);
         }
     }
     //        imagefilter($image, IMG_FILTER_GRAYSCALE);
     imagejpeg($image, $destination);
     //        $rgb = imagecolorat($image, 10, 15);
     //        $r = ($rgb >> 16) & 0xFF;
     //        $g = ($rgb >> 8) & 0xFF;
     //        $b = $rgb & 0xFF;
     //
     //        var_dump($r, $g, $b);
     return "<img src='" . base_url() . "/" . $destination . "'/>";
 }
开发者ID:Kaelcao,项目名称:cbir,代码行数:39,代码来源:Converter.php

示例9: by_lines

 function by_lines($image, &$size_x, &$size_y)
 {
     $lines = array();
     $size_x = imagesx($image->get_handle());
     $size_y = imagesy($image->get_handle());
     $dest_img = imagecreatetruecolor($size_x, $size_y);
     imagecopymerge($dest_img, $image->get_handle(), 0, 0, 0, 0, $size_x, $size_y, 100);
     // initialize line length counter
     $ctr = 0;
     for ($y = 0; $y < $size_y; $y++) {
         $line = "";
         for ($x = 0; $x < $size_x; $x++) {
             // Save image pixel to the stream data
             $rgb = ImageColorAt($dest_img, $x, $y);
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             $line .= sprintf("%02X%02X%02X", min(max($r, 0), 255), min(max($g, 0), 255), min(max($b, 0), 255));
             // Increate the line length counter; check if stream line needs to be terminated
             $ctr += 6;
             if ($ctr > MAX_LINE_LENGTH) {
                 $line .= "\n";
                 $ctr = 0;
             }
         }
         $lines[] = $line;
     }
     return $lines;
 }
开发者ID:isantiago,项目名称:foswiki,代码行数:29,代码来源:ps.l2.image.encoder.stream.inc.php

示例10: image2ascii

/**
 * Converting an image to ascii art.
 *
 * @author	PHPPRO	http://www.phpro.org/examples/Image-To-Ascii-Art-With-PHP.html
 * 
 * @param mixed	binary or string of an image
 **/
function image2ascii($image)
{
    // return value
    $ret = '';
    // open the image
    // $img = imagecreatefromjpeg($image); PHPPRO originally do this
    $img = imagecreatefromstring($image);
    // my little hack
    // get width and height
    $width = imagesx($img);
    $height = imagesy($img);
    // loop for height
    for ($h = 0; $h < $height; $h++) {
        // loop for height
        for ($w = 0; $w <= $width; $w++) {
            // add color
            $rgb = ImageColorAt($img, $w, $h);
            $r = $rgb >> 16 & 0xff;
            $g = $rgb >> 8 & 0xff;
            $b = $rgb & 0xff;
            // create a hex value from the rgb
            $hex = '#' . str_pad(dechex($r), 2, '0', STR_PAD_LEFT) . str_pad(dechex($g), 2, '0', STR_PAD_LEFT) . str_pad(dechex($b), 2, '0', STR_PAD_LEFT);
            // now add to the return string and we are done
            if ($w == $width) {
                $ret .= '<br>';
            } else {
                $ret .= '<b style="color:' . $hex . ';">#</b>';
            }
        }
    }
    return $ret;
}
开发者ID:segellabs,项目名称:Image-to-ASCII-Art-Converter,代码行数:39,代码来源:image2ascii.php

示例11: mainColor

function mainColor($image)
{
    $i = 0;
    for ($x = 0; $x < imagesx($image); $x++) {
        for ($y = 0; $y < imagesy($image); $y++) {
            $rgb = ImageColorAt($image, $x, $y);
            $r += $rgb >> 16 & 0xff;
            $g += $rgb >> 8 & 0xff;
            $b += $rgb & 0xff;
            $i++;
        }
    }
    return imageColorAllocate($image, $r / $i, $g / $i, $b / $i);
}
开发者ID:BackupTheBerlios,项目名称:ascore,代码行数:14,代码来源:lib_image.php

示例12: getColors

 private function getColors($image, $width, $height)
 {
     $colors = array();
     for ($i = 0; $i < $width; $i++) {
         for ($j = 0; $j < $height; $j++) {
             $rgb = ImageColorAt($image, $i, $j);
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             $colors[serialize(array($r, $g, $b))]++;
         }
     }
     $colors = $this->sortColors($colors);
     return $colors;
 }
开发者ID:MichalKatuscak,项目名称:FontColorByImage,代码行数:15,代码来源:FontColorByImage.class.php

示例13: NewColorizeImage

 function NewColorizeImage($img, $targetColor, $baseColor)
 {
     $targetHexArr = $this->c->hex82hex($targetColor);
     $targetColor = $targetHexArr[0];
     $alpha = $targetHexArr[1];
     $c1 = $this->c->hex2hsl($baseColor);
     $c2 = $this->c->hex2hsl($targetColor);
     $im = imagecreatefrompng($img);
     $height = imagesy($im);
     $width = imagesx($im);
     $imnew = imagecreatetruecolor($width, $height);
     imagealphablending($imnew, false);
     imagesavealpha($imnew, true);
     $transparent = imagecolorallocatealpha($imnew, 255, 255, 255, 127);
     imagefilledrectangle($imnew, 0, 0, $width, $height, $transparent);
     $rgb = $this->rgb2array($targetColor);
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $rgba = ImageColorAt($im, $x, $y);
             $rgb = array($rgba >> 16 & 0xff, $rgba >> 8 & 0xff, $rgba & 0xff);
             $hsl = $this->c->rgb2hsl($rgb);
             $a[0] = $hsl[0] + ($c2[0] - $c1[0]);
             $a[1] = $hsl[1] * ($c2[1] / ($c1[1] == 0 ? 1.0E-5 : $c1[1]));
             if ($a[1] > 1) {
                 $a[1] = 1;
             }
             $a[2] = exp(log($hsl[2]) * log($c2[2]) / log($c1[2]));
             if ($a[2] > 1) {
                 $a[2] = 1;
             }
             $rgb = $this->c->hsl2rgb($a);
             $A = 0xfe - ($rgba >> 24) * 2 & 0xff;
             $A = (int) ($A * (hexdec($alpha) / 0xfe));
             if ($A > 0xff) {
                 $A = 0xff;
             }
             $A = (int) ((0xfe - $A) / 2);
             imagesetpixel($imnew, $x, $y, imagecolorallocatealpha($imnew, $rgb[0], $rgb[1], $rgb[2], $A));
         }
     }
     $hash = md5($img . $targetColor . $alpha) . '.png';
     imagepng($imnew, $this->cache . DS . $hash);
     imagedestroy($imnew);
     imagedestroy($im);
     return $hash;
 }
开发者ID:knigherrant,项目名称:decopatio,代码行数:46,代码来源:Helper.class.php

示例14: image_resize_sepia

function image_resize_sepia(&$src_im, $quality = 60)
{
    $src_x = ceil(imagesx($src_im));
    $src_y = ceil(imagesy($src_im));
    $dst_x = $src_x;
    $dst_y = $src_y;
    $dst_im = ImageCreateTrueColor($dst_x, $dst_y);
    // Benötigt PHP > 4.3.2
    if (function_exists('imageantialias')) {
        imageantialias($dst_im, TRUE);
    }
    ImageCopyResampled($dst_im, $src_im, 0, 0, 0, 0, $dst_x, $dst_y, $src_x, $src_y);
    // Change style of image pixelwise
    for ($y = 0; $y < $dst_y; $y++) {
        for ($x = 0; $x < $dst_x; $x++) {
            $col = ImageColorAt($dst_im, $x, $y);
            $r = ($col & 0xff0000) >> 16;
            $g = ($col & 0xff00) >> 8;
            $b = $col & 0xff;
            $grey = (min($r, $g, $b) + max($r, $g, $b)) / 2;
            // Boost  colors
            $boost = 1.2;
            $boostborder = 250;
            for ($i = 0; $i < 25; $i++) {
                if ($grey > $boostborder) {
                    $grey = $grey * $boost;
                    break;
                }
                $boost -= 0.01;
                $boostborder -= 10;
            }
            // Set sepia palette
            $r = $grey * 1.01;
            $g = $grey * 0.98;
            $b = $grey * 0.9;
            // Correct max values
            $r = $r > 255 ? 255 : $r;
            $g = $g > 255 ? 255 : $g;
            $b = $b > 255 ? 255 : $b;
            $col = ImageColorAllocate($dst_im, $r, $g, $b);
            ImageSetPixel($dst_im, $x, $y, $col);
        }
    }
    $src_im = $dst_im;
}
开发者ID:BackupTheBerlios,项目名称:redaxo-svn,代码行数:45,代码来源:filter.sepia.inc.php

示例15: colorizeImage

 function colorizeImage($img, $targetColor, $baseColor)
 {
     $cachefile = $this->_folder . 'colorize' . md5($img) . $targetColor . $baseColor . '.' . $this->_filetype;
     if (!NextendFilesystem::existsFile($cachefile)) {
         $targetHexArr = NextendColor::hex82hex($targetColor);
         $targetColor = $targetHexArr[0];
         $alpha = hexdec($targetHexArr[1]);
         $c1 = NextendColor::hex2hsl($baseColor);
         $c2 = NextendColor::hex2hsl($targetColor);
         $im = imagecreatefrompng($img);
         $width = imagesx($im);
         $height = imagesy($im);
         $this->createIm($width, $height);
         $rgb = NextendColor::rgb2array($targetColor);
         for ($x = 0; $x < $width; $x++) {
             for ($y = 0; $y < $height; $y++) {
                 $rgba = ImageColorAt($im, $x, $y);
                 $rgb = array($rgba >> 16 & 0xff, $rgba >> 8 & 0xff, $rgba & 0xff);
                 $hsl = NextendColor::rgb2hsl($rgb);
                 $a[0] = $hsl[0] + ($c2[0] - $c1[0]);
                 $a[1] = $hsl[1] * ($c2[1] / $c1[1]);
                 if ($a[1] > 1) {
                     $a[1] = 1;
                 }
                 $a[2] = exp(log($hsl[2]) * log($c2[2]) / log($c1[2]));
                 if ($a[2] > 1) {
                     $a[2] = 1;
                 }
                 $rgb = NextendColor::hsl2rgb($a);
                 $A = 0xff - ($rgba >> 24) * 2 & 0xff;
                 $A = (int) ($A * ($alpha / 0xff));
                 if ($A > 0xff) {
                     $A = 0xff;
                 }
                 $A = (int) ((0xff - $A) / 2);
                 imagesetpixel($this->_im, $x, $y, imagecolorallocatealpha($this->_im, $rgb[0], $rgb[1], $rgb[2], $A));
             }
         }
         $this->saveIm($cachefile);
         imagedestroy($im);
     }
     return NextendFilesystem::pathToAbsoluteURL($cachefile);
 }
开发者ID:Gordondalos,项目名称:smart-event,代码行数:43,代码来源:image.php


注:本文中的ImageColorAt函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。