Пример #1
1
 public function getAvatar($string, $widthHeight = 12, $theme = 'default')
 {
     $widthHeight = max($widthHeight, 12);
     $md5 = md5($string);
     $fileName = _TMP_DIR_ . '/' . $md5 . '.png';
     if ($this->tmpFileExists($fileName)) {
         return $fileName;
     }
     // Create seed.
     $seed = intval(substr($md5, 0, 6), 16);
     mt_srand($seed);
     $body = array('legs' => mt_rand(0, count($this->availableParts[$theme]['legs']) - 1), 'hair' => mt_rand(0, count($this->availableParts[$theme]['hair']) - 1), 'arms' => mt_rand(0, count($this->availableParts[$theme]['arms']) - 1), 'body' => mt_rand(0, count($this->availableParts[$theme]['body']) - 1), 'eyes' => mt_rand(0, count($this->availableParts[$theme]['eyes']) - 1), 'mouth' => mt_rand(0, count($this->availableParts[$theme]['mouth']) - 1));
     // Avatar random parts.
     $parts = array('legs' => $this->availableParts[$theme]['legs'][$body['legs']], 'hair' => $this->availableParts[$theme]['hair'][$body['hair']], 'arms' => $this->availableParts[$theme]['arms'][$body['arms']], 'body' => $this->availableParts[$theme]['body'][$body['body']], 'eyes' => $this->availableParts[$theme]['eyes'][$body['eyes']], 'mouth' => $this->availableParts[$theme]['mouth'][$body['mouth']]);
     $avatar = imagecreate($widthHeight, $widthHeight);
     imagesavealpha($avatar, true);
     imagealphablending($avatar, false);
     $background = imagecolorallocate($avatar, 0, 0, 0);
     $line_colour = imagecolorallocate($avatar, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55);
     imagecolortransparent($avatar, $background);
     imagefilledrectangle($avatar, 0, 0, $widthHeight, $widthHeight, $background);
     // Fill avatar with random parts.
     foreach ($parts as &$part) {
         $this->drawPart($part, $avatar, $widthHeight, $line_colour, $background);
     }
     imagepng($avatar, $fileName);
     imagecolordeallocate($avatar, $line_colour);
     imagecolordeallocate($avatar, $background);
     imagedestroy($avatar);
     return $fileName;
 }
Пример #2
0
 function save($file)
 {
     // 透過処理
     if ($this->info[2] == IMAGETYPE_GIF || $this->info[2] == IMAGETYPE_PNG) {
         // 元画像の透過色を取得する。
         $trnprt_indx = imagecolortransparent($this->image);
         // 透過色が設定されている場合は透過処理を行う。
         if ($trnprt_indx < 0 && $this->info[2] == IMAGETYPE_PNG) {
             // アルファブレンディングをOFFにする。
             imagealphablending($this->image, false);
             // 生成した透過色を変換後画像の透過色として設定
             imagesavealpha($this->image, true);
         }
     }
     switch ($this->info[2]) {
         case IMAGETYPE_GIF:
             imagegif($this->image, $file);
             break;
         case IMAGETYPE_JPEG:
         case IMAGETYPE_JPEG2000:
             imagejpeg($this->image, $file, 100);
             break;
         case IMAGETYPE_PNG:
             imagepng($this->image, $file);
             break;
         default:
             break;
     }
 }
Пример #3
0
 /**
  * Reduces colors of a given image
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $count = $this->argument(0)->value();
     $matte = $this->argument(1)->value();
     // get current image size
     $size = $image->getSize();
     // create empty canvas
     $resource = imagecreatetruecolor($size->width, $size->height);
     // define matte
     if (is_null($matte)) {
         $matte = imagecolorallocatealpha($resource, 255, 255, 255, 127);
     } else {
         $matte = $image->getDriver()->parseColor($matte)->getInt();
     }
     // fill with matte and copy original image
     imagefill($resource, 0, 0, $matte);
     // set transparency
     imagecolortransparent($resource, $matte);
     // copy original image
     imagecopy($resource, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height);
     if (is_numeric($count) && $count <= 256) {
         // decrease colors
         imagetruecolortopalette($resource, true, $count);
     }
     // set new resource
     $image->setCore($resource);
     return true;
 }
Пример #4
0
 /**
  * 生成验证码
  * @param  string $file 图片保存文件名,不指定则图片会被直接输出
  * @return null
  */
 public function get($file = "")
 {
     $support = $this->support();
     list($code, $answer) = $this->generateCode();
     $image = null;
     @session_start();
     $_SESSION['vitex.captcha.answer'] = strtolower($answer);
     if ($support == 'imagick') {
         $image = new \Imagick();
         $image->newImage($this->width, $this->height, "none");
         $image->setImageFormat('png');
         $image = $this->imagickLine($image, $this->linenum);
         $image = $this->imagickDrawText($image, $code);
         $image->swirlImage(30);
         $image->oilPaintImage(1);
         if ($file) {
             $image->writeImage($file);
         } else {
             header("Content-type:image/png");
             echo $image->getImageBlob();
         }
     } else {
         $image = imagecreate($this->width, $this->height);
         $color = imagecolorallocate($image, 255, 255, 255);
         imagecolortransparent($image, $color);
         $this->gdLine($image, $this->linenum);
         $this->gdDrawText($image, $code);
         if ($file) {
             imagepng($image, $file);
         } else {
             header("Content-type: image/jpeg; Cache-Control: no-store, no-cache, must-revalidate");
             imagepng($image);
         }
     }
 }
 protected function createMask(sfImage $image, $w, $h)
 {
     // Create a mask png image of the area you want in the circle/ellipse (a 'magicpink' image with a black shape on it, with black set to the colour of alpha transparency) - $mask
     $mask = $image->getAdapter()->getTransparentImage($w, $h);
     // Set the masking colours
     if (false === $this->getColor() || 'image/png' == $image->getMIMEType()) {
         $mask_black = imagecolorallocate($mask, 0, 0, 0);
     } else {
         $mask_black = $image->getAdapter()->getColorByHex($mask, $this->getColor());
     }
     // Cannot use white as transparent mask if color is set to white
     if ($this->getColor() === '#FFFFFF' || $this->getColor() === false) {
         $mask_transparent = imagecolorallocate($mask, 255, 0, 0);
     } else {
         $mask_color = imagecolorsforindex($mask, imagecolorat($image->getAdapter()->getHolder(), 0, 0));
         $mask_transparent = imagecolorallocate($mask, $mask_color['red'], $mask_color['green'], $mask_color['blue']);
     }
     imagecolortransparent($mask, $mask_transparent);
     imagefill($mask, 0, 0, $mask_black);
     // Draw the rounded rectangle for the mask
     $this->imagefillroundedrect($mask, 0, 0, $w, $h, $this->getRadius(), $mask_transparent);
     $mask_image = clone $image;
     $mask_image->getAdapter()->setHolder($mask);
     return $mask_image;
 }
Пример #6
0
 public function resize($width = 0, $height = 0)
 {
     if (!$this->info['width'] || !$this->info['height']) {
         return;
     }
     $scale = min($width / $this->info['width'], $height / $this->info['height']);
     if ($scale == 1 && $this->info['mime'] != 'image/png') {
         return;
     }
     $new_width = (int) ($this->info['width'] * $scale);
     $new_height = (int) ($this->info['height'] * $scale);
     $xpos = (int) (($width - $new_width) / 2);
     $ypos = (int) (($height - $new_height) / 2);
     $image_old = $this->image;
     $this->image = imagecreatetruecolor($width, $height);
     if (isset($this->info['mime']) && $this->info['mime'] == 'image/png') {
         imagealphablending($this->image, false);
         imagesavealpha($this->image, true);
         $background = imagecolorallocatealpha($this->image, 255, 255, 255, 127);
         imagecolortransparent($this->image, $background);
     } else {
         $background = imagecolorallocate($this->image, 255, 255, 255);
     }
     imagefilledrectangle($this->image, 0, 0, $width, $height, $background);
     imagecopyresampled($this->image, $image_old, $xpos, $ypos, 0, 0, $new_width, $new_height, $this->info['width'], $this->info['height']);
     imagedestroy($image_old);
     $this->info['width'] = $width;
     $this->info['height'] = $height;
 }
Пример #7
0
 protected function setResource()
 {
     $this->resource = imagecreatetruecolor($this->background->width, $this->background->height);
     if (isset($this->fill) === true) {
         $backgroundindex = imagecolorallocate($this->resource, $this->fill['red'], $this->fill['green'], $this->fill['blue']);
         imagefill($this->resource, 0, 0, $backgroundindex);
     } else {
         if ($this->format === 'gif') {
             $backgroundindex = imagecolorallocatealpha($this->resource, 255, 255, 255, 127);
             imagefill($this->resource, 0, 0, $backgroundindex);
             imagecolortransparent($this->resource, $backgroundindex);
         } else {
             if ($this->format === 'jpeg') {
                 $backgroundindex = imagecolorallocate($this->resource, 255, 255, 255);
                 imagefill($this->resource, 0, 0, $backgroundindex);
             } else {
                 if ($this->format === 'png') {
                     imagealphablending($this->resource, false);
                     imagesavealpha($this->resource, true);
                     $backgroundindex = imagecolorallocatealpha($this->resource, 255, 255, 255, 127);
                     imagefill($this->resource, 0, 0, $backgroundindex);
                     imagealphablending($this->resource, true);
                 }
             }
         }
     }
 }
Пример #8
0
 function PrintReport()
 {
     header("Content-type: image/png");
     //建立画布大小
     $this->IMAGE = imagecreate($this->X, $this->Y);
     //设定画布背景色
     $background = imagecolorallocate($this->IMAGE, $this->R, $this->G, $this->B);
     //背影透明与否
     if ($this->TRANSPARENT == "1") {
         imagecolortransparent($this->IMAGE, $background);
     } else {
         //如不要透明时可填充背景色
         imagefilledrectangle($this->IMAGE, 0, 0, $this->X, $this->Y, $background);
     }
     //参数字体大小及颜色
     $this->FONTCOLOR = imagecolorallocate($this->IMAGE, 255 - $this->R, 255 - $this->G, 255 - $this->B);
     //根据REPORTTYPE选择是竖柱状、横柱状还是线状
     switch ($this->REPORTTYPE) {
         case "0":
             break;
         case "1":
             $this->imageColumnS();
             break;
         case "2":
             $this->imageColumnH();
             break;
         case "3":
             $this->imageLine();
             break;
     }
     //调用print打印xy坐标轴、图片
     $this->printXY();
     $this->printAll();
 }
Пример #9
0
function reldis_createFile($filename, $uga_part, $agga_part)
{
    $im_uga = @ImageCreateFromPng("good.png");
    $im_agga = @ImageCreateFromPng("bad.png");
    if (!$im_uga || !$im_agga) {
        die("Cannot Initialize new GD image stream");
    }
    $width = imagesx($im_uga);
    $sum = $uga_part + $agga_part;
    $uga_part /= $sum;
    $agga_part /= $sum;
    $uga_part *= $width;
    $agga_part *= $width;
    $im = @ImageCreate($width, $width);
    $white = imagecolorallocate($im, 0xff, 0xff, 0xff);
    imagefill($im, 0, 0, $white);
    imagecolortransparent($im, $white);
    $left = 0;
    imagecopy($im, $im_uga, $left, 0, $left, 0, $uga_part + 1, $width);
    $left += $uga_part;
    imagecopy($im, $im_agga, $left, 0, $left, 0, $agga_part + 1, $width);
    header("Content-type: image/png");
    imagepng($im, $filename);
    imagedestroy($im);
}
Пример #10
0
function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale)
{
    list($imagewidth, $imageheight, $imageType) = getimagesize($image);
    $imageType = image_type_to_mime_type($imageType);
    $newImageWidth = ceil($width * $scale);
    $newImageHeight = ceil($height * $scale);
    $newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
    switch ($imageType) {
        case "image/png":
        case "image/x-png":
            $source = imagecreatefrompng($image);
            break;
    }
    imagecopyresampled($newImage, $source, 0, 0, $start_width, $start_height, $newImageWidth, $newImageHeight, $width, $height);
    switch ($imageType) {
        case "image/png":
        case "image/x-png":
            $transcol = imagecolorallocatealpha($newImage, 255, 0, 255, 127);
            $trans = imagecolortransparent($newImage, $transcol);
            imagefill($newImage, 0, 0, $transcol);
            imagesavealpha($newImage, true);
            imagealphablending($newImage, true);
            imagepng($newImage, $thumb_image_name);
            break;
    }
    chmod($thumb_image_name, 0777);
}
Пример #11
0
 public function loadFile($thumbnail, $image)
 {
     $imgData = @GetImageSize($image);
     if (!$imgData) {
         throw new Exception(sprintf('Could not load image %s', $image));
     }
     if (in_array($imgData['mime'], $this->imgTypes)) {
         $loader = $this->imgLoaders[$imgData['mime']];
         if (!function_exists($loader)) {
             throw new Exception(sprintf('Function %s not available. Please enable the GD extension.', $loader));
         }
         $this->source = $loader($image);
         $this->sourceWidth = $imgData[0];
         $this->sourceHeight = $imgData[1];
         $this->sourceMime = $imgData['mime'];
         $thumbnail->initThumb($this->sourceWidth, $this->sourceHeight, $this->maxWidth, $this->maxHeight, $this->scale, $this->inflate);
         $this->thumb = imagecreatetruecolor($thumbnail->getThumbWidth(), $thumbnail->getThumbHeight());
         imagecolortransparent($this->thumb, imagecolorallocate($this->thumb, 0, 0, 0));
         imagealphablending($this->thumb, false);
         imagesavealpha($this->thumb, true);
         if ($imgData[0] == $this->maxWidth && $imgData[1] == $this->maxHeight) {
             $this->thumb = $this->source;
         } else {
             imagecopyresampled($this->thumb, $this->source, 0, 0, 0, 0, $thumbnail->getThumbWidth(), $thumbnail->getThumbHeight(), $imgData[0], $imgData[1]);
         }
         return true;
     } else {
         throw new Exception(sprintf('Image MIME type %s not supported', $imgData['mime']));
     }
 }
Пример #12
0
function a(&$g)
{
    $a = imagecolorallocate($g, 0, 0, 0);
    imagecolortransparent($g, $a);
    imagealphablending($g, 0);
    imagesavealpha($g, 1);
}
Пример #13
0
 function Create_pics($thumbnail, $source, $path, $ext)
 {
     global $CONFIG_GALLERY;
     imagecolortransparent($source, imagecolorallocate($source, 0, 0, 0));
     imagealphablending($source, false);
     $path_mini = str_replace('pics', 'pics/thumbnails', $path);
     if (function_exists('imagegif') && $ext === 'gif') {
         imagegif($thumbnail, $path_mini);
     } elseif (function_exists('imagejpeg') && $ext === 'jpg') {
         imagejpeg($thumbnail, $path_mini, $CONFIG_GALLERY['quality']);
     } elseif (function_exists('imagepng') && $ext === 'png') {
         imagepng($thumbnail, $path_mini);
     } else {
         $this->error = 'e_no_graphic_support';
     }
     switch ($ext) {
         case 'jpg':
             @imagejpeg($source, $path);
             break;
         case 'gif':
             @imagegif($source, $path);
             break;
         case 'png':
             @imagepng($source, $path);
             break;
         default:
             $this->error = 'e_no_graphic_support';
     }
 }
Пример #14
0
function generate_image_memetext($text, $width = 400, $height = 400)
{
    global $submit, $ppath, $textpos, $updown, $textcaps, $mainimg;
    if ($submit) {
        $txt_img = imagecreatefromjpeg($ppath . 'images/main/' . basename($mainimg, '.jpg') . '.jpg');
    } else {
        $txt_img = imagecreatetruecolor($width, $height);
    }
    $transbak = imagecolorallocate($txt_img, 0, 0, 0);
    $trans = imagecolorallocatealpha($txt_img, 255, 255, 255, 255);
    if ($submit === false) {
        imagecolortransparent($txt_img, $transbak);
        imagefill($txt_img, 0, 0, $trans);
        imagealphablending($txt_img, true);
    }
    $pos = 1;
    $i = 0;
    foreach ($text as $tx) {
        if ($textcaps[$i] === 'caps') {
            $tx = strtoupper($tx);
        } elseif ($textcaps[$i] === 'small') {
            $tx = strtolower($tx);
        }
        meme_text($txt_img, $tx, $pos++, (int) $textpos[$i], $updown[$i]);
        $i++;
    }
    if ($submit) {
        imagejpeg($txt_img, $ppath . 'images/meme/' . $_POST['mid'] . '.jpg', 100);
    } else {
        imagepng($txt_img);
    }
    imagedestroy($txt_img);
}
Пример #15
0
 function img_bundle()
 {
     $sources = func_get_args();
     $target = array_shift($sources);
     $this->sizeinfo = array();
     $this->vpos = 0;
     $this->wpos = 0;
     foreach ($sources as $src) {
         $this->_bundle_index($src);
     }
     $target_img = imagecreatetruecolor($this->wpos, $this->vpos);
     $bg_color = imagecolorallocate($target_img, 255, 0, 255);
     //牺牲掉这个最丑的颜色做透明背景
     //todo:智能选择调色板中没有的颜色
     imagefilledrectangle($target_img, 0, 0, $this->wpos, $this->vpos, $bg_color);
     $app = $params['app'] ? app::get($params['app']) : $this->app;
     foreach ($this->sizeinfo as $file => $info) {
         $src_img = imagecreatefromgif($app->res_dir . '/' . $file);
         $rst = imagecopy($target_img, $src_img, 0, $info[0], 0, 0, $info[1], $info[2]);
         //            $rst = imagecopyresampled($target_img,$src_img,0,$info[0],0,0,$info[1],$info[2],$info[1],$info[2]);
         //            $rst = imagecopyresized($target_img,$src_img,0,$info[0],0,0,$info[1],$info[2],$info[1],$info[2]);
         $src_img = null;
     }
     imagecolortransparent($target_img, $bg_color);
     //        imagetruecolortopalette($target_img,true,256);
     //todo:优化显示效果
     imagegif($target_img, $app->res_dir . '/' . $target);
     $target_img = null;
     $rs = fopen($app->res_dir . '/' . $target, 'a');
     $info = serialize($this->sizeinfo);
     fwrite($rs, pack('a*V', $info, strlen($info)));
     fclose($rs);
     $this->sizeinfo = null;
 }
Пример #16
0
function fixart($id, $hue, $show)
{
    if (!file_exists("images/art/fixedart_" . $id . "_" . $hue . ".png")) {
        if (!file_exists("images/art/art_" . $id . "_" . $hue . ".png")) {
            include "art.php";
            createart($id, $hue, 0);
        }
        $imgurl = "images/art/art_" . $id . "_" . $hue . ".png";
        $img = imagecreatefrompng("{$imgurl}");
        $box = imageTrimBox($img);
        $img2 = imagecreatetruecolor($box['w'], $box['h']);
        imagecopy($img2, $img, 0, 0, $box['l'], $box['t'], $box['w'], $box['h']);
        imagepng($img2, 'images/art/fixedart_' . $id . '_' . $hue . '.png', 0, NULL);
        imagedestroy($img);
        imagedestroy($img2);
    }
    if ($show == 1) {
        Header("Content-type: image/png");
        Header("Content-disposition: inline; filename=art_" . $id . "_" . $hue . ".png");
        $img = imagecreatefrompng("images/art/fixedart_" . $id . "_" . $hue . ".png");
        $black = imagecolorallocate($img, 0, 0, 0);
        imagecolortransparent($img, $black);
        imagepng($img);
        imagedestroy($img);
        return;
    }
}
 function create_error($text)
 {
     $text = $text;
     $size = "8";
     $font = "classes/fonts/trebuchet.ttf";
     $TextBoxSize = imagettfbbox($size, 0, $font, preg_replace("/\\[br\\]/is", "\r\n", $text));
     $TxtBx_Lwr_L_x = $TextBoxSize[0];
     $TxtBx_Lwr_L_y = $TextBoxSize[1];
     $TxtBx_Lwr_R_x = $TextBoxSize[2];
     $TxtBx_Lwr_R_y = $TextBoxSize[3];
     $TxtBx_Upr_R_x = $TextBoxSize[4];
     $TxtBx_Upr_R_y = $TextBoxSize[5];
     $TxtBx_Upr_L_x = $TextBoxSize[6];
     $TxtBx_Upr_L_y = $TextBoxSize[7];
     $width = max($TxtBx_Lwr_R_x, $TxtBx_Upr_R_x) - min($TxtBx_Lwr_L_x, $TxtBx_Upr_L_x);
     $height = max($TxtBx_Lwr_L_y, $TxtBx_Lwr_R_y) - min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
     $x = -min($TxtBx_Upr_L_x, $TxtBx_Lwr_L_x);
     $y = -min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
     $img = imagecreate($width + 2, $height + 1);
     // Only PHP-Version 4.3.2 or higher
     if (function_exists('imageantialias')) {
         imageantialias($img, FALSE);
     }
     $white = imagecolorallocate($img, 255, 255, 255);
     $black = imagecolorallocate($img, 0, 0, 0);
     imagecolortransparent($img, $white);
     ImageTTFText($img, $size, 0, $x, $y, $black, $font, preg_replace("/<br>/is", "\r\n", $text));
     header("Content-Type: image/png");
     ImagePNG($img);
     ImageDestroy($img);
     exit;
 }
Пример #18
0
 /**
  * @param Frame $frame
  * @param $index
  * @return resource
  */
 protected function render(Frame $frame, $index)
 {
     if ($index == 0) {
         $screenSize = $this->decoder->getScreenSize();
         $im = imagecreatetruecolor($screenSize->getWidth(), $screenSize->getHeight());
         imagealphablending($im, false);
         imagesavealpha($im, true);
         $transColor = imagecolortransparent($im, imagecolorallocatealpha($im, 255, 255, 255, 127));
         imagefill($im, 0, 0, $transColor);
         $this->frameCurrent = $im;
         $this->framePrevious = $frame;
         $this->copyFrameToBuffer($frame);
         return $this->frameCurrent;
     }
     imagepalettetotruecolor($this->frameCurrent);
     $disposalMethod = $this->framePrevious->getDisposalMethod();
     if ($disposalMethod === 0 || $disposalMethod === 1) {
         $this->copyFrameToBuffer($frame);
     } elseif ($disposalMethod === 2) {
         $this->restoreToBackground($this->framePrevious, imagecolortransparent($this->frameCurrent));
         $this->copyFrameToBuffer($frame);
     } else {
         throw new \RuntimeException("Disposal method {$disposalMethod} is not implemented.");
     }
     $this->framePrevious = $frame;
     return $this->frameCurrent;
 }
Пример #19
0
 /**
  * Add an image to the generator.
  *
  * This function adds a source image to the generator. It serves two main purposes: add a source image if one was
  * not supplied to the constructor and to add additional source images so that different images can be supplied for
  * different sized images in the resulting ICO file. For instance, a small source image can be used for the small
  * resolutions while a larger source image can be used for large resolutions.
  *
  * @param string $file Path to the source image file.
  * @param array $sizes Optional. An array of sizes (each size is an array with a width and height) that the source image should be rendered at in the generated ICO file. If sizes are not supplied, the size of the source image will be used.
  * @return boolean true on success and false on failure.
  */
 public function add_image($file, $sizes = array())
 {
     if (!$this->_has_requirements) {
         return false;
     }
     if (false === ($im = $this->_load_image_file($file))) {
         return false;
     }
     if (empty($sizes)) {
         $sizes = array(imagesx($im), imagesy($im));
     }
     // If just a single size was passed, put it in array.
     if (!is_array($sizes[0])) {
         $sizes = array($sizes);
     }
     foreach ((array) $sizes as $size) {
         list($width, $height) = $size;
         $new_im = imagecreatetruecolor($width, $height);
         imagecolortransparent($new_im, imagecolorallocatealpha($new_im, 0, 0, 0, 127));
         imagealphablending($new_im, false);
         imagesavealpha($new_im, true);
         $source_width = imagesx($im);
         $source_height = imagesy($im);
         if (false === imagecopyresampled($new_im, $im, 0, 0, 0, 0, $width, $height, $source_width, $source_height)) {
             continue;
         }
         $this->_add_image_data($new_im);
     }
     return true;
 }
Пример #20
0
 /**
  * 生成略缩图
  * 
  * @param string $srcFile     		源图片
  * @param string $dstFile     		略缩图保存位置
  * @param int $dstW           		略缩图宽度
  * @param string $dstH        		略缩图高度
  * @param string $isProportion      略缩图是否等比略缩,默认为false
  * @return array|boolean
  */
 public static function makeThumb($srcFile, $dstFile, $dstW, $dstH, $isProportion = FALSE)
 {
     if (false === ($minitemp = self::getThumbInfo($srcFile, $dstW, $dstH, $isProportion))) {
         return false;
     }
     list($imagecreate, $imagecopyre) = self::getImgcreate($minitemp['type']);
     if (!$imagecreate) {
         return false;
     }
     $imgwidth = $minitemp['width'];
     $imgheight = $minitemp['height'];
     $srcX = $srcY = $dstX = $dstY = 0;
     if (!$isProportion) {
         $dsDivision = $imgheight / $imgwidth;
         $fixDivision = $dstH / $dstW;
         if ($dsDivision > $fixDivision) {
             $tmp = $imgwidth * $fixDivision;
             $srcY = round(($imgheight - $tmp) / 2);
             $imgheight = $tmp;
         } else {
             $tmp = $imgheight / $fixDivision;
             $srcX = round(($imgwidth - $tmp) / 2);
             $imgwidth = $tmp;
         }
     }
     $thumb = $imagecreate($minitemp['dstW'], $minitemp['dstH']);
     if (function_exists('imagecolorallocate') && function_exists('imagecolortransparent')) {
         $black = imagecolorallocate($thumb, 0, 0, 0);
         imagecolortransparent($thumb, $black);
     }
     $imagecopyre($thumb, $minitemp['source'], $dstX, $dstY, $srcX, $srcY, $minitemp['dstW'], $minitemp['dstH'], $imgwidth, $imgheight);
     self::makeImg($minitemp['type'], $thumb, $dstFile);
     imagedestroy($thumb);
     return array('width' => $minitemp['dstW'], 'height' => $minitemp['dstH'], 'type' => $minitemp['type']);
 }
Пример #21
0
 /**
  * Wrapper function for 'imagecopyresampled'
  *
  * @param  Image   $image
  * @param  integer $dst_x
  * @param  integer $dst_y
  * @param  integer $src_x
  * @param  integer $src_y
  * @param  integer $dst_w
  * @param  integer $dst_h
  * @param  integer $src_w
  * @param  integer $src_h
  * @return boolean
  */
 protected function modify($image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
 {
     foreach ($image as $frame) {
         // create new image
         $modified = imagecreatetruecolor($dst_w, $dst_h);
         // get current image
         $resource = $frame->getCore();
         // preserve transparency
         $transIndex = imagecolortransparent($resource);
         if ($transIndex != -1) {
             $rgba = imagecolorsforindex($modified, $transIndex);
             $transColor = imagecolorallocatealpha($modified, $rgba['red'], $rgba['green'], $rgba['blue'], 127);
             imagefill($modified, 0, 0, $transColor);
             imagecolortransparent($modified, $transColor);
         } else {
             imagealphablending($modified, false);
             imagesavealpha($modified, true);
         }
         // copy content from resource
         imagecopyresampled($modified, $resource, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
         // free memory of old core
         imagedestroy($resource);
         // set new content as recource
         $frame->setCore($modified);
     }
     return true;
 }
Пример #22
0
 function run()
 {
     global $dynbasepath, $rootpath;
     $MAX_LEN = 630;
     $totalWidth = 0;
     $counter = 0;
     $im = imagecreatetruecolor($MAX_LEN, 80);
     $alpha = imagecolorallocate($im, 255, 255, 255);
     imagefilledrectangle($im, 0, 0, 800, 80, $alpha);
     imagecolortransparent($im, $alpha);
     $numbers = $this->mrand(1, 50, 50);
     while ($totalWidth < $MAX_LEN && $counter < 10) {
         $number = $numbers[$counter];
         $path = $rootpath . 'images/header/header_' . $number . '.jpg';
         $tmp = imagecreatefromjpeg($path);
         $totalWidth += imagesx($tmp);
         /*  echo "total=".$totalWidth;
             echo "<br />";
             echo "im_".$number."=".imagesx($tmp); */
         if ($totalWidth >= $MAX_LEN) {
             // return the real width od final logo
             $totalWidth -= imagesx($tmp);
             break;
         }
         imagecopy($im, $tmp, $totalWidth - imagesx($tmp), 0, 0, 0, imagesx($tmp), imagesy($tmp));
         $counter++;
     }
     $im_final = imagecreatetruecolor($totalWidth, 80);
     imagecopy($im_final, $im, 0, 0, 0, 0, $totalWidth, 80);
     imagejpeg($im_final, $rootpath . "images/header/logo.jpg", 90);
     imagedestroy($im);
     imagedestroy($im_final);
 }
Пример #23
0
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = imagecreatetruecolor($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, 255, 0, 255);
     $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
     imagecolortransparent($base_image, $col[0]);
     imagealphablending($base_image, true);
     imagesavealpha($base_image, true);
     //        imagefill($base_image, 0, 0, $col[0]);
     imagefill($base_image, 0, 0, 0x7fff0000);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
 /**
  * @return ZipInterface
  */
 public function render()
 {
     $pathThumbnail = $this->getPresentation()->getPresentationProperties()->getThumbnailPath();
     if ($pathThumbnail) {
         // Size : 128x128 pixel
         // PNG : 8bit, non-interlaced with full alpha transparency
         $gdImage = imagecreatefromstring(file_get_contents($pathThumbnail));
         if ($gdImage) {
             list($width, $height) = getimagesize($pathThumbnail);
             $gdRender = imagecreatetruecolor(128, 128);
             $colorBgAlpha = imagecolorallocatealpha($gdRender, 0, 0, 0, 127);
             imagecolortransparent($gdRender, $colorBgAlpha);
             imagefill($gdRender, 0, 0, $colorBgAlpha);
             imagecopyresampled($gdRender, $gdImage, 0, 0, 0, 0, 128, 128, $width, $height);
             imagetruecolortopalette($gdRender, false, 255);
             imagesavealpha($gdRender, true);
             ob_start();
             imagepng($gdRender);
             $imageContents = ob_get_contents();
             ob_end_clean();
             imagedestroy($gdRender);
             imagedestroy($gdImage);
             $this->getZip()->addFromString('Thumbnails/thumbnail.png', $imageContents);
         }
     }
     return $this->getZip();
 }
Пример #25
0
function foundation_process_image_file($file_name, $setting_name)
{
    if ($setting_name->domain == FOUNDATION_SETTING_DOMAIN && $setting_name->name == 'logo_image') {
        // Need to make sure this isn't too big
        if (function_exists('getimagesize') && function_exists('imagecreatefrompng') && function_exists('imagecopyresampled') && function_exists('imagepng')) {
            $size = getimagesize($file_name);
            if ($size) {
                $width = $size[0];
                $height = $size[1];
                if ($size['mime'] == 'image/png') {
                    if ($width > FOUNDATION_MAX_LOGO_SIZE) {
                        $new_width = FOUNDATION_MAX_LOGO_SIZE;
                        $new_height = $height * $new_width / $width;
                        $src_image = imagecreatefrompng($file_name);
                        $saved_image = imagecreatetruecolor($new_width, $new_height);
                        // Preserve Transparency
                        imagecolortransparent($saved_image, imagecolorallocate($saved_image, 0, 0, 0));
                        imagecopyresampled($saved_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                        // Get rid of the old file
                        unlink($file_name);
                        // New image, compression level 5 (make it a bit smaller)
                        imagepng($saved_image, $file_name, 5);
                    }
                }
            }
        }
    }
}
Пример #26
0
 private function generateImage()
 {
     // prepare image
     $this->generatedImage = imagecreatetruecolor($this->getPixelRatio() * 5, $this->getPixelRatio() * 5);
     $rgbBackgroundColor = $this->getBackgroundColor();
     if (null === $rgbBackgroundColor) {
         $background = imagecolorallocate($this->generatedImage, 0, 0, 0);
         imagecolortransparent($this->generatedImage, $background);
     } else {
         $background = imagecolorallocate($this->generatedImage, $rgbBackgroundColor[0], $rgbBackgroundColor[1], $rgbBackgroundColor[2]);
         imagefill($this->generatedImage, 0, 0, $background);
     }
     // prepage color
     $rgbColor = $this->getColor();
     $gdColor = imagecolorallocate($this->generatedImage, $rgbColor[0], $rgbColor[1], $rgbColor[2]);
     // draw content
     foreach ($this->getArrayOfSquare() as $lineKey => $lineValue) {
         foreach ($lineValue as $colKey => $colValue) {
             if (true === $colValue) {
                 imagefilledrectangle($this->generatedImage, $colKey * $this->getPixelRatio(), $lineKey * $this->getPixelRatio(), ($colKey + 1) * $this->getPixelRatio(), ($lineKey + 1) * $this->getPixelRatio(), $gdColor);
             }
         }
     }
     return $this;
 }
Пример #27
0
 /**
  * Cria a imagem apartir dos dados do Sprite.
  */
 public function createImage()
 {
     $img = imagecreatetruecolor($this->width, $this->height);
     //http://in.php.net/manual/en/function.imagecreatetruecolor.php
     imagecolortransparent($img, imagecolorallocatealpha($img, $this->palette[0]['red'], $this->palette[0]['green'], $this->palette[0]['blue'], $this->palette[0]['alpha']));
     $i = 0;
     $p = 0;
     while ($i < strlen($this->data)) {
         $b = ord($this->data[$i]);
         //http://in.php.net/manual/en/function.ord.php
         if ($b == 0) {
             $i++;
             $dest = $p + ord($this->data[$i]);
             $color = imagecolorallocatealpha($img, $this->palette[0]['red'], $this->palette[0]['green'], $this->palette[0]['blue'], $this->palette[0]['alpha']);
             //http://in.php.net/manual/en/function.imagecolorallocatealpha.php
             for ($p; $p < $dest; $p++) {
                 imagesetpixel($img, $p % $this->width, $p / $this->width, $color);
             }
         } else {
             $color = imagecolorallocatealpha($img, $this->palette[$b]['red'], $this->palette[$b]['green'], $this->palette[$b]['blue'], $this->palette[$b]['alpha']);
             imagesetpixel($img, $p % $this->width, $p / $this->width, $color);
             //http://in.php.net/manual/en/function.imagesetpixel.php
             $p++;
         }
         $i++;
     }
     return $img;
 }
Пример #28
0
 /**
  * Displays the captcha image
  *
  * @access  public
  * @param   int     $key    Captcha key
  * @return  mixed   Captcha raw image data
  */
 function image($key)
 {
     $value = Jaws_Utils::RandomText();
     $result = $this->update($key, $value);
     if (Jaws_Error::IsError($result)) {
         $value = '';
     }
     $bg = dirname(__FILE__) . '/resources/simple.bg.png';
     $im = imagecreatefrompng($bg);
     imagecolortransparent($im, imagecolorallocate($im, 255, 255, 255));
     // Write it in a random position..
     $darkgray = imagecolorallocate($im, 0x10, 0x70, 0x70);
     $x = 5;
     $y = 20;
     $text_length = strlen($value);
     for ($i = 0; $i < $text_length; $i++) {
         $fnt = rand(7, 10);
         $y = rand(6, 10);
         imagestring($im, $fnt, $x, $y, $value[$i], $darkgray);
         $x = $x + rand(15, 25);
     }
     header("Content-Type: image/png");
     ob_start();
     imagepng($im);
     $content = ob_get_contents();
     ob_end_clean();
     imagedestroy($im);
     return $content;
 }
 public function resize_image($size, $mimetype, $option = 'auto')
 {
     // Get optimal width and height based on $size
     $newwidth = $size['w'];
     $newheight = $size['h'];
     $optionarray = $this->get_dimensions($newwidth, $newheight, $option);
     $optimalwidth = $optionarray['optimalwidth'];
     $optimalheight = $optionarray['optimalheight'];
     $this->imageresized = imagecreatetruecolor($optimalwidth, $optimalheight);
     if ($mimetype == 'image/png' || $mimetype == 'image/gif') {
         // Create a new destination image which is completely
         // transparent and turn off alpha blending for it, so that when
         // the PNG source file is copied, the alpha channel is retained
         // Thanks to http://alexle.net/archives/131
         $background = imagecolorallocate($this->imageresized, 0, 0, 0);
         imagecolortransparent($this->imageresized, $background);
         imagealphablending($this->imageresized, false);
         imagecopyresampled($this->imageresized, $this->image, 0, 0, 0, 0, $optimalwidth, $optimalheight, $this->width, $this->height);
         imagesavealpha($this->imageresized, true);
     } else {
         imagecopyresampled($this->imageresized, $this->image, 0, 0, 0, 0, $optimalwidth, $optimalheight, $this->width, $this->height);
     }
     if ($option == 'crop') {
         $this->crop($optimalwidth, $optimalheight, $newwidth, $newheight);
     }
     imagedestroy($this->image);
 }
Пример #30
-1
 function output()
 {
     $arr = $this->ret;
     $bg = DATA_DIR . '/cache/vcodebg.png';
     $image = imagecreatefrompng($bg);
     list($w, $baseH) = getimagesize($bg);
     header('Content-type: image/png');
     $x = 1;
     foreach ($arr as $i => $filename) {
         list($w, $h) = getimagesize($filename);
         $source = imagecreatefrompng($filename);
         $t_id = imagecolortransparent($source);
         $rotate = imagerotate($source, rand(-20, 20), $t_id);
         $w2 = $w * $baseH / $h;
         imagecopyresized($image, $rotate, $x, 0, 0, 0, $w2, $baseH, $w, $h);
         imagedestroy($source);
         imagedestroy($rotate);
         $x += $w2;
     }
     $x += 1;
     $dst = imagecreatetruecolor($x, $baseH);
     imagecopyresampled($dst, $image, 0, 0, 0, 0, $x, $baseH, $x, $baseH);
     imagepng($dst);
     imagedestroy($image);
     imagedestroy($dst);
     exit;
 }