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


PHP ImageColorsForIndex函数代码示例

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


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

示例1: 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

示例2: 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

示例3: GetPixelColor

 /**
  * Retourne la couleur d'un pixel dans une image
  *
  * @param ressource $img
  * @param int $x
  * @param int $y
  * @return array|bool
  */
 public static function GetPixelColor(&$img, $x, $y)
 {
     if (!is_resource($img)) {
         return false;
     }
     return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
 }
开发者ID:xablen,项目名称:Semaine14_SPIP_test,代码行数:15,代码来源:filtres_images_lib_mini.php

示例4: _antialisedSubPixel

 /**
  * Antialias'es the pixel around x,y with weights a,b
  *
  * @param int $x X point
  * @param int $y Y point
  * @param int $a The weight of the current color
  * @param int $b The weight of the applied/wanted color
  * @param mixed $color The pixel color
  * @access private
  */
 function _antialisedSubPixel($x, $y, $a, $b, $color)
 {
     $x = $this->_getX($x);
     $y = $this->_getX($y);
     if ($x >= 0 && $y >= 0 && $x < $this->getWidth() && $y < $this->getHeight()) {
         $tempColor = ImageColorsForIndex($this->_canvas, ImageColorAt($this->_canvas, $x, $y));
         $newColor[0] = min(255, round($tempColor['red'] * $a + $color['red'] * $b));
         $newColor[1] = min(255, round($tempColor['green'] * $a + $color['green'] * $b));
         $newColor[2] = min(255, round($tempColor['blue'] * $a + $color['blue'] * $b));
         //$newColor[3] = 0;
         $color = '#';
         foreach ($newColor as $acolor) {
             $color .= sprintf('%02s', dechex($acolor));
         }
         $newColor = $this->_color($color);
         //,'rgb(' . $newColor[0] . ',' . $newColor[1] . ','  . $newColor[2] .')';
         ImageSetPixel($this->_canvas, $x, $y, $newColor);
     }
 }
开发者ID:chiranjeevjain,项目名称:agilebill,代码行数:29,代码来源:GD.php

示例5: resize

 /**
  * From: https://stackoverflow.com/questions/4590441/php-thumbnail-image-resizing-with-proportions
  */
 function resize(&$img, $size)
 {
     if (!is_numeric($size)) {
         $size = explode('x', $size);
     }
     if (is_array($size)) {
         $maxwidth = $size[0];
         $maxheight = $size[1];
     } else {
         if ($size) {
             $maxwidth = $size;
             $maxheight = $size;
         }
     }
     $width = imagesx($img);
     $height = imagesy($img);
     if (!ALLOW_BLOATING) {
         if ($maxwidth > $width) {
             $maxwidth = $width;
         }
         if ($maxheight > $height) {
             $maxheight = $height;
         }
     }
     if ($height > $width) {
         $ratio = $maxheight / $height;
         $newheight = $maxheight;
         $newwidth = $width * $ratio;
     } else {
         $ratio = $maxwidth / $width;
         $newwidth = $maxwidth;
         $newheight = $height * $ratio;
     }
     $newimg = imagecreatetruecolor($newwidth, $newheight);
     $palsize = ImageColorsTotal($img);
     for ($i = 0; $i < $palsize; $i++) {
         $colors = ImageColorsForIndex($img, $i);
         ImageColorAllocate($newimg, $colors['red'], $colors['green'], $colors['blue']);
     }
     imagefill($newimg, 0, 0, IMG_COLOR_TRANSPARENT);
     imagesavealpha($newimg, true);
     imagealphablending($newimg, true);
     imagecopyresampled($newimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
     $img = $newimg;
 }
开发者ID:shyswork,项目名称:pictshare,代码行数:48,代码来源:image.php

示例6: imageCopyResampledBicubic

 public static function imageCopyResampledBicubic(&$dst_image, &$src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
 {
     // We should first cut the piece we are interested in from the source
     $src_img = ImageCreateTrueColor($src_w, $src_h);
     imagecopy($src_img, $src_image, 0, 0, $src_x, $src_y, $src_w, $src_h);
     // This one is used as temporary image
     $dst_img = ImageCreateTrueColor($dst_w, $dst_h);
     ImagePaletteCopy($dst_img, $src_img);
     $rX = $src_w / $dst_w;
     $rY = $src_h / $dst_h;
     $w = 0;
     for ($y = 0; $y < $dst_h; $y++) {
         $ow = $w;
         $w = round(($y + 1) * $rY);
         $t = 0;
         for ($x = 0; $x < $dst_w; $x++) {
             $r = $g = $b = 0;
             $a = 0;
             $ot = $t;
             $t = round(($x + 1) * $rX);
             for ($u = 0; $u < $w - $ow; $u++) {
                 for ($p = 0; $p < $t - $ot; $p++) {
                     $c = ImageColorsForIndex($src_img, ImageColorAt($src_img, $ot + $p, $ow + $u));
                     $r += $c['red'];
                     $g += $c['green'];
                     $b += $c['blue'];
                     $a++;
                 }
             }
             ImageSetPixel($dst_img, $x, $y, ImageColorClosest($dst_img, $r / $a, $g / $a, $b / $a));
         }
     }
     // Apply the temp image over the returned image and use the destination x,y coordinates
     imagecopy($dst_image, $dst_img, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h);
     // We should return true since ImageCopyResampled/ImageCopyResized do it
     return true;
 }
开发者ID:densem-2013,项目名称:exikom,代码行数:37,代码来源:image.php

示例7: inputLevels

 /**
  * Apply input levels to input image pointer (increasing contrast)
  *
  * @param resource $im GDlib Image Pointer
  * @param int $low The "low" value (close to 0)
  * @param int $high The "high" value (close to 255)
  * @return void
  */
 public function inputLevels(&$im, $low, $high)
 {
     if ($low < $high) {
         $low = MathUtility::forceIntegerInRange($low, 0, 255);
         $high = MathUtility::forceIntegerInRange($high, 0, 255);
         $delta = $high - $low;
         $totalCols = ImageColorsTotal($im);
         for ($c = 0; $c < $totalCols; $c++) {
             $cols = ImageColorsForIndex($im, $c);
             $cols['red'] = MathUtility::forceIntegerInRange(($cols['red'] - $low) / $delta * 255, 0, 255);
             $cols['green'] = MathUtility::forceIntegerInRange(($cols['green'] - $low) / $delta * 255, 0, 255);
             $cols['blue'] = MathUtility::forceIntegerInRange(($cols['blue'] - $low) / $delta * 255, 0, 255);
             ImageColorSet($im, $c, $cols['red'], $cols['green'], $cols['blue']);
         }
     }
 }
开发者ID:TYPO3Incubator,项目名称:TYPO3.CMS,代码行数:24,代码来源:GraphicalFunctions.php

示例8: upgrade_profile_image

/**
 * Given a user id this function scales and crops the user images to remove
 * the one pixel black border.
 *
 * @global object
 * @param int $id
 * @param string $dir
 * @return boolean
 */
function upgrade_profile_image($id, $dir = 'users')
{
    global $CFG, $OUTPUT;
    $im = ImageCreateFromJPEG($CFG->dataroot . '/' . $dir . '/' . $id . '/f1.jpg');
    if (function_exists('ImageCreateTrueColor') and $CFG->gdversion >= 2) {
        $im1 = ImageCreateTrueColor(100, 100);
        $im2 = ImageCreateTrueColor(35, 35);
    } else {
        $im1 = ImageCreate(100, 100);
        $im2 = ImageCreate(35, 35);
    }
    if (function_exists('ImageCopyResampled') and $CFG->gdversion >= 2) {
        ImageCopyBicubic($im1, $im, 0, 0, 2, 2, 100, 100, 96, 96);
    } else {
        imagecopy($im1, $im, 0, 0, 0, 0, 100, 100);
        $c = ImageColorsForIndex($im1, ImageColorAt($im1, 2, 2));
        $color = ImageColorClosest($im1, $c['red'], $c['green'], $c['blue']);
        ImageSetPixel($im1, 0, 0, $color);
        $c = ImageColorsForIndex($im1, ImageColorAt($im1, 2, 97));
        $color = ImageColorClosest($im1, $c['red'], $c['green'], $c['blue']);
        ImageSetPixel($im1, 0, 99, $color);
        $c = ImageColorsForIndex($im1, ImageColorAt($im1, 97, 2));
        $color = ImageColorClosest($im1, $c['red'], $c['green'], $c['blue']);
        ImageSetPixel($im1, 99, 0, $color);
        $c = ImageColorsForIndex($im1, ImageColorAt($im1, 97, 97));
        $color = ImageColorClosest($im1, $c['red'], $c['green'], $c['blue']);
        ImageSetPixel($im1, 99, 99, $color);
        for ($x = 1; $x < 99; $x++) {
            $c1 = ImageColorsForIndex($im1, ImageColorAt($im, $x, 1));
            $color = ImageColorClosest($im, $c1['red'], $c1['green'], $c1['blue']);
            ImageSetPixel($im1, $x, 0, $color);
            $c2 = ImageColorsForIndex($im1, ImageColorAt($im1, $x, 98));
            $color = ImageColorClosest($im, $c2['red'], $c2['green'], $c2['blue']);
            ImageSetPixel($im1, $x, 99, $color);
        }
        for ($y = 1; $y < 99; $y++) {
            $c3 = ImageColorsForIndex($im1, ImageColorAt($im, 1, $y));
            $color = ImageColorClosest($im, $c3['red'], $c3['green'], $c3['blue']);
            ImageSetPixel($im1, 0, $y, $color);
            $c4 = ImageColorsForIndex($im1, ImageColorAt($im1, 98, $y));
            $color = ImageColorClosest($im, $c4['red'], $c4['green'], $c4['blue']);
            ImageSetPixel($im1, 99, $y, $color);
        }
    }
    ImageCopyBicubic($im2, $im, 0, 0, 2, 2, 35, 35, 96, 96);
    if (function_exists('ImageJpeg')) {
        if (ImageJpeg($im1, $CFG->dataroot . '/' . $dir . '/' . $id . '/f1.jpg', 90) and ImageJpeg($im2, $CFG->dataroot . '/' . $dir . '/' . $id . '/f2.jpg', 95)) {
            @chmod($CFG->dataroot . '/' . $dir . '/' . $id . '/f1.jpg', 0666);
            @chmod($CFG->dataroot . '/' . $dir . '/' . $id . '/f2.jpg', 0666);
            return 1;
        }
    } else {
        echo $OUTPUT->notification('PHP has not been configured to support JPEG images.  Please correct this.');
    }
    return 0;
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:65,代码来源:gdlib.php

示例9: GD2BMPstring

 public function GD2BMPstring(&$gd_image)
 {
     // Author: James Heinrich
     // Purpose: Save file as type bmp
     // Param in: The image canvas (passed as ref)
     $imageX = ImageSX($gd_image);
     $imageY = ImageSY($gd_image);
     $BMP = '';
     for ($y = $imageY - 1; $y >= 0; $y--) {
         $thisline = '';
         for ($x = 0; $x < $imageX; $x++) {
             $argb = ImageColorsForIndex($gd_image, @ImageColorAt($gd_image, $x, $y));
             $thisline .= chr($argb['blue']) . chr($argb['green']) . chr($argb['red']);
         }
         while (strlen($thisline) % 4) {
             $thisline .= "";
         }
         $BMP .= $thisline;
     }
     $bmpSize = strlen($BMP) + 14 + 40;
     // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp
     $BITMAPFILEHEADER = 'BM';
     // WORD bfType;
     $BITMAPFILEHEADER .= $this->LittleEndian2String($bmpSize, 4);
     // DWORD bfSize;
     $BITMAPFILEHEADER .= $this->LittleEndian2String(0, 2);
     // WORD bfReserved1;
     $BITMAPFILEHEADER .= $this->LittleEndian2String(0, 2);
     // WORD bfReserved2;
     $BITMAPFILEHEADER .= $this->LittleEndian2String(54, 4);
     // DWORD bfOffBits;
     // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp
     $BITMAPINFOHEADER = $this->LittleEndian2String(40, 4);
     // DWORD biSize;
     $BITMAPINFOHEADER .= $this->LittleEndian2String($imageX, 4);
     // LONG biWidth;
     $BITMAPINFOHEADER .= $this->LittleEndian2String($imageY, 4);
     // LONG biHeight;
     $BITMAPINFOHEADER .= $this->LittleEndian2String(1, 2);
     // WORD biPlanes;
     $BITMAPINFOHEADER .= $this->LittleEndian2String(24, 2);
     // WORD biBitCount;
     $BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4);
     // DWORD biCompression;
     $BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4);
     // DWORD biSizeImage;
     $BITMAPINFOHEADER .= $this->LittleEndian2String(2835, 4);
     // LONG biXPelsPerMeter;
     $BITMAPINFOHEADER .= $this->LittleEndian2String(2835, 4);
     // LONG biYPelsPerMeter;
     $BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4);
     // DWORD biClrUsed;
     $BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4);
     // DWORD biClrImportant;
     return $BITMAPFILEHEADER . $BITMAPINFOHEADER . $BMP;
 }
开发者ID:nukeplus,项目名称:nuke,代码行数:56,代码来源:Image.php

示例10: Resize_Image

 function Resize_Image($src, $width = 0, $height = 0, $dst)
 {
     if ($height <= 0 && $width <= 0) {
         return false;
     }
     // Setting defaults and meta
     $image = '';
     $final_width = 0;
     $final_height = 0;
     list($width_old, $height_old, $image_type) = GetImageSize($src);
     // Calculating proportionality
     if ($width == 0) {
         $factor = $height / $height_old;
     } elseif ($height == 0) {
         $factor = $width / $width_old;
     } else {
         $factor = Min($width / $width_old, $height / $height_old);
     }
     $final_width = Round($width_old * $factor);
     $final_height = Round($height_old * $factor);
     // Loading image to memory according to type
     switch ($image_type) {
         case IMAGETYPE_GIF:
             $image = imagecreatefromgif($src);
             break;
         case IMAGETYPE_JPEG:
             $image = imagecreatefromjpeg($src);
             break;
         case IMAGETYPE_PNG:
             $image = imagecreatefrompng($src);
             break;
         default:
             return false;
     }
     // This is the resizing/resampling/transparency-preserving magic
     $image_resized = ImageCreateTrueColor($final_width, $final_height);
     if ($image_type == IMAGETYPE_GIF || $image_type == IMAGETYPE_PNG) {
         $transparency = ImageColorTransparent($image);
         if ($image_type == IMAGETYPE_GIF && $transparency >= 0) {
             list($r, $g, $b) = Array_Values(ImageColorsForIndex($image, $transparency));
             $transparency = ImageColorAllocate($image_resized, $r, $g, $b);
             Imagefill($image_resized, 0, 0, $transparency);
             ImageColorTransparent($image_resized, $transparency);
         } elseif ($image_type == IMAGETYPE_PNG) {
             ImageAlphaBlending($image_resized, false);
             $color = ImageColorAllocateAlpha($image_resized, 0, 0, 0, 127);
             ImageFill($image_resized, 0, 0, $color);
             ImageSaveAlpha($image_resized, true);
         }
     }
     ImageCopyResampled($image_resized, $image, 0, 0, 0, 0, $final_width, $final_height, $width_old, $height_old);
     // Writing image
     switch ($image_type) {
         case IMAGETYPE_GIF:
             imagegif($image_resized, $dst);
             break;
         case IMAGETYPE_JPEG:
             imagejpeg($image_resized, $dst, 85);
             break;
         case IMAGETYPE_PNG:
             imagepng($image_resized, $dst);
             break;
         default:
             return false;
     }
 }
开发者ID:rtgibbons,项目名称:bya.org,代码行数:66,代码来源:wp-plugin-auto-resize-uploaded-images.php

示例11: resize

 /**
  * From: https://stackoverflow.com/questions/4590441/php-thumbnail-image-resizing-with-proportions
  */
 function resize(&$img, $size)
 {
     $pm = new PictshareModel();
     $sd = $pm->sizeStringToWidthHeight($size);
     $maxwidth = $sd['width'];
     $maxheight = $sd['height'];
     $width = imagesx($img);
     $height = imagesy($img);
     if (!ALLOW_BLOATING) {
         if ($maxwidth > $width) {
             $maxwidth = $width;
         }
         if ($maxheight > $height) {
             $maxheight = $height;
         }
     }
     if ($height > $width) {
         $ratio = $maxheight / $height;
         $newheight = $maxheight;
         $newwidth = $width * $ratio;
     } else {
         $ratio = $maxwidth / $width;
         $newwidth = $maxwidth;
         $newheight = $height * $ratio;
     }
     $newimg = imagecreatetruecolor($newwidth, $newheight);
     $palsize = ImageColorsTotal($img);
     for ($i = 0; $i < $palsize; $i++) {
         $colors = ImageColorsForIndex($img, $i);
         ImageColorAllocate($newimg, $colors['red'], $colors['green'], $colors['blue']);
     }
     imagefill($newimg, 0, 0, IMG_COLOR_TRANSPARENT);
     imagesavealpha($newimg, true);
     imagealphablending($newimg, true);
     imagecopyresampled($newimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
     $img = $newimg;
 }
开发者ID:cavebeat,项目名称:pictshare,代码行数:40,代码来源:image.php

示例12: ImageColorsForIndex

<?php

$transparent = ImageColorsForIndex($image, ImageColorTransparent($image));
print_r($transparent);
开发者ID:zmwebdev,项目名称:PHPcookbook-code-3ed,代码行数:4,代码来源:transparent3.php

示例13: imagecreate

     // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
     $zoom = $twidth / $currwidth;
     // Length Ratio For Height
     $newwidth = $twidth;
     // Width Is Equal To Max Width
     $newheight = $currheight * $zoom;
     // Creates The New Height
 }
 $dimg = imagecreate($newwidth, $newheight);
 // Make New Image For Thumbnail
 imagetruecolortopalette($simg, false, 256);
 // Create New Color Pallete
 $palsize = ImageColorsTotal($simg);
 for ($i = 0; $i < $palsize; $i++) {
     // Counting Colors In The Image
     $colors = ImageColorsForIndex($simg, $i);
     // Number Of Colors Used
     ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);
     // Tell The Server What Colors This Image Will Use
 }
 imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
 // Copy Resized Image To The New Image (So We Can Save It)
 imagejpeg($dimg, "{$tdir}" . $_SESSION['user']['username'] . '.jpg');
 // Saving The Image
 imagedestroy($simg);
 // Destroying The Temporary Image
 imagedestroy($dimg);
 // Destroying The Other Temporary Image
 print 'Image thumbnail created successfully.';
 // Resize successful
 $user = new User(array('id' => $_SESSION['user']['id'], 'avatar' => $_SESSION['user']['username'] . '.jpg'));
开发者ID:JJWTimmer,项目名称:BLAM,代码行数:31,代码来源:usermgr.php

示例14: GetPixelColor

 private function GetPixelColor(&$img, $x, $y)
 {
     # Author:     James Heinrich
     # Purpose:
     # Param in:
     # Param out:
     # Reference:
     # Notes:#
     if (!is_resource($img)) {
         return false;
     }
     return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
 }
开发者ID:visualweber,项目名称:appzf1,代码行数:13,代码来源:imageLib.php

示例15: __invoke

 public function __invoke()
 {
     $view = $this->view;
     $pixObject = $this->pixObject;
     $id = $pixObject->getId();
     $title = $pixObject->getTitle();
     $pixname = $pixObject->getPicture();
     $filepix = "/usr/local/apache2/html/uploads/";
     $filepix .= $this->username;
     $filepix .= "/pix/";
     $pix = $filepix . $pixname;
     // Check to see that the thumbnail exists.
     $thumbPixName = "large_" . $pixname;
     $thumbPix = $filepix . $thumbPixName;
     if (!file_exists($thumbPix)) {
         $img = imagecreatefromjpeg($pix);
         $width = imagesx($img);
         $height = imagesy($img);
         $whlog = "width: " . $width . " height " . $height;
         //determine which side is the longest to use in calculating length of the shorter side, since the longest will be the max size for whichever side is longest.
         if ($height > $width) {
             $ratio = 160 / $height;
             $newheight = 160;
             $newwidth = $width * $ratio;
         } else {
             $ratio = 160 / $width;
             $newwidth = 160;
             $newheight = $height * $ratio;
         }
         $whlog = "newwidth: " . $newwidth . " newheight " . $newheight;
         //create new image resource to hold the resized image
         $newimg = imagecreatetruecolor($newwidth, $newheight);
         $palsize = ImageColorsTotal($img);
         //Get palette size for original image
         for ($i = 0; $i < $palsize; $i++) {
             $colors = ImageColorsForIndex($img, $i);
             ImageColorAllocate($newimg, $colors['red'], $colors['green'], $colors['blue']);
         }
         //copy original image into new image at new size.
         imagecopyresized($newimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
         imagejpeg($newimg, $thumbPix);
         //$output file is the path/filename where you wish to save the file.
     }
     $base = 'https://newhollandpress.com/pix/view/';
     $base .= urlencode($id);
     return $view->partial("/items/pix.phtml");
     /*
         	$output = "<div id='" . $this->itemId . "' class='itemHelper_Wide'>";
     		$output .= "<ul>";
     		$output .= "<li>";
     		$output .= "<span>Pix</span>";
     		$output .= "</li>";
     		$output .= "<li>";
     		$output .= "<a href='" . $base . "'>" . $id . "</a>";
     		$output .= "</li>";
     		$output .= "<li>";
     		$output .= $pixObject->getPicture();
     		$output .= "</li>";
     		$output .= "<li>";
     		$output .= "<img src='https://www.newhollandpress.com/uploads/";
     		$output .= $this->username;
     		$output .= "/pix/";
     		$output .= $thumbPixName;
     		$output .= "'>";
     		$output .= "</li>";
     		$output .= "</ul>";
     		$output .= "</div>";
     		
     		return $output;
     * 
     */
 }
开发者ID:newhollandpress,项目名称:nhp,代码行数:72,代码来源:PixHelper.php


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