예제 #1
0
function image_createThumb($src, $dest, $maxWidth, $maxHeight, $quality = 75)
{
    if (file_exists($src) && isset($dest)) {
        // path info
        $destInfo = pathInfo($dest);
        // image src size
        $srcSize = getImageSize($src);
        // image dest size $destSize[0] = width, $destSize[1] = height
        $srcRatio = $srcSize[0] / $srcSize[1];
        // width/height ratio
        $destRatio = $maxWidth / $maxHeight;
        if ($destRatio > $srcRatio) {
            $destSize[1] = $maxHeight;
            $destSize[0] = $maxHeight * $srcRatio;
        } else {
            $destSize[0] = $maxWidth;
            $destSize[1] = $maxWidth / $srcRatio;
        }
        // path rectification
        if ($destInfo['extension'] == "gif") {
            $dest = substr_replace($dest, 'jpg', -3);
        }
        // true color image, with anti-aliasing
        $destImage = imageCreateTrueColor($destSize[0], $destSize[1]);
        //       imageAntiAlias($destImage,true);
        // src image
        switch ($srcSize[2]) {
            case 1:
                //GIF
                $srcImage = imageCreateFromGif($src);
                break;
            case 2:
                //JPEG
                $srcImage = imageCreateFromJpeg($src);
                break;
            case 3:
                //PNG
                $srcImage = imageCreateFromPng($src);
                break;
            default:
                return false;
                break;
        }
        // resampling
        imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destSize[0], $destSize[1], $srcSize[0], $srcSize[1]);
        // generating image
        switch ($srcSize[2]) {
            case 1:
            case 2:
                imageJpeg($destImage, $dest, $quality);
                break;
            case 3:
                imagePng($destImage, $dest);
                break;
        }
        return true;
    } else {
        return 'No such File';
    }
}
예제 #2
0
 function generate_png($file_path, $size, $stars, $value, $output = '')
 {
     $image_set = imagecreatefrompng($file_path);
     $star_empty = imagecreatetruecolor($size, $size);
     imagesavealpha($star_empty, true);
     $star_empty_transparent = imagecolorallocatealpha($star_empty, 0, 0, 0, 127);
     imagefill($star_empty, 0, 0, $star_empty_transparent);
     $star_filled = imagecreatetruecolor($size, $size);
     imagesavealpha($star_filled, true);
     $star_filled_transparent = imagecolorallocatealpha($star_filled, 0, 0, 0, 127);
     imagefill($star_filled, 0, 0, $star_filled_transparent);
     imagecopy($star_empty, $image_set, 0, 0, 0, 0, $size, $size);
     imagecopy($star_filled, $image_set, 0, 0, 0, $size * 2, $size, $size);
     $image = imageCreateTrueColor($stars * $size, $size);
     imagesavealpha($image, true);
     $image_transparent = imagecolorallocatealpha($image, 0, 0, 0, 127);
     imagefill($image, 0, 0, $image_transparent);
     imageSetTile($image, $star_empty);
     imagefilledrectangle($image, 0, 0, $stars * $size, $size, IMG_COLOR_TILED);
     imageSetTile($image, $star_filled);
     imagefilledrectangle($image, 0, 0, $value * $size, $size, IMG_COLOR_TILED);
     if ($output == '') {
         Header("Content-type: image/png");
         imagepng($image);
     } else {
         imagepng($image, $output);
     }
     imagedestroy($image);
     imagedestroy($image_set);
     imagedestroy($star_empty);
     imagedestroy($star_filled);
 }
예제 #3
0
function thumbnail($PicPathIn, $PicPathOut, $PicFilenameIn, $PicFilenameOut, $neueHoehe, $Quality)
{
    // Bilddaten ermitteln
    $size = getimagesize("{$PicPathIn}" . "{$PicFilenameIn}");
    $breite = $size[0];
    $hoehe = $size[1];
    $neueBreite = intval($breite * $neueHoehe / $hoehe);
    if ($size[2] == 1) {
        // GIF
        $altesBild = ImageCreateFromGIF("{$PicPathIn}" . "{$PicFilenameIn}");
        $neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
        imageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
    }
    if ($size[2] == 2) {
        // JPG
        $altesBild = ImageCreateFromJPEG("{$PicPathIn}" . "{$PicFilenameIn}");
        $neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
        ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
    }
    if ($size[2] == 3) {
        // PNG
        $altesBild = ImageCreateFromPNG("{$PicPathIn}" . "{$PicFilenameIn}");
        $neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
        ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
    }
}
function imageResize($file, $info, $destination)
{
    $height = $info[1];
    //высота
    $width = $info[0];
    //ширина
    //определяем размеры будущего превью
    $y = 150;
    if ($width > $height) {
        $x = $y * ($width / $height);
    } else {
        $x = $y / ($height / $width);
    }
    $to = imageCreateTrueColor($x, $y);
    switch ($info['mime']) {
        case 'image/jpeg':
            $from = imageCreateFromJpeg($file);
            break;
        case 'image/png':
            $from = imageCreateFromPng($file);
            break;
        case 'image/gif':
            $from = imageCreateFromGif($file);
            break;
        default:
            echo "No prevue";
            break;
    }
    imageCopyResampled($to, $from, 0, 0, 0, 0, imageSX($to), imageSY($to), imageSX($from), imageSY($from));
    imagepng($to, $destination);
    imagedestroy($from);
    imagedestroy($to);
}
예제 #5
0
파일: image.php 프로젝트: kolydart/SEBLOD
 public function createThumb($image, $tnumber, $twidth, $theight, $tformat, $quality = 100)
 {
     if (!($twidth && trim($twidth) != '' && is_numeric($twidth)) && !($theight && trim($theight) != '' && is_numeric($theight))) {
         return false;
     }
     $path = $this->_pathinfo['dirname'];
     $resImage = $this->_resource;
     // Calcul Thumb Size
     $values = $this->_prepareDimensions($this->_width, $this->_height, $twidth, $theight, $tformat);
     list($thumbX, $thumbY, $newX, $newY, $thumbWidth, $thumbHeight, $newWidth, $newHeight) = $values;
     // Add transparence for PNG
     $thumbImage = imageCreateTrueColor($thumbWidth, $thumbHeight);
     if ($this->_extension == 'png') {
         imagealphablending($thumbImage, false);
     }
     // Generate thumb ressource
     imagecopyresampled($thumbImage, $resImage, $thumbX, $thumbY, $newX, $newY, $thumbWidth, $thumbHeight, $newWidth, $newHeight);
     // Set Folder
     // $file_path ='';
     if ($tnumber == 0) {
         $thumbLocation = $path . '/' . $this->_pathinfo['basename'];
     } else {
         JCckDevHelper::createFolder($path . '/_thumb' . $tnumber);
         $thumbLocation = $path . '/_thumb' . $tnumber . '/' . $this->_pathinfo['basename'];
     }
     // Create image
     $this->_generateThumb($this->_extension, $thumbImage, $thumbLocation, $quality);
     return true;
 }
예제 #6
0
function resize_image_crop($src_image, $width, $height)
{
    $src_width = imageSX($src_image);
    $src_height = imageSY($src_image);
    $width = $width <= 0 ? $src_width : $width;
    $height = $height <= 0 ? $src_height : $height;
    $prop_width = $src_width / $width;
    $prop_height = $src_height / $height;
    if ($prop_height > $prop_width) {
        $crop_width = $src_width;
        $crop_height = round($prop_width * $height);
        $srcX = 0;
        $srcY = round($src_height / 2) - round($crop_height / 2);
    } else {
        $crop_width = round($prop_height * $width);
        $crop_height = $src_height;
        $srcX = round($src_width / 2) - round($crop_width / 2);
        $srcY = 0;
    }
    $new_image = imageCreateTrueColor($width, $height);
    $tmp_image = imageCreateTrueColor($crop_width, $crop_height);
    imageCopy($tmp_image, $src_image, 0, 0, $srcX, $srcY, $crop_width, $crop_height);
    imageCopyResampled($new_image, $tmp_image, 0, 0, 0, 0, $width, $height, $crop_width, $crop_height);
    imagedestroy($tmp_image);
    image_unsharp_mask($new_image);
    return $new_image;
}
예제 #7
0
 /**
  * Crop image file and set coordinates
  */
 public function update()
 {
     $x = fRequest::get('x', 'integer');
     $y = fRequest::get('y', 'integer');
     $w = fRequest::get('w', 'integer');
     $h = fRequest::get('h', 'integer');
     $img_w = fRequest::get('img_w', 'integer');
     $img_h = fRequest::get('img_h', 'integer');
     try {
         // throw new Exception(sprintf('x=%d,y=%d,w=%d,h=%d,img_w=%d,img_h=%d', $x, $y, $w, $h, $img_w, $img_h));
         $img_r = imagecreatefromjpeg($this->uploadfile);
         $x = $x * imagesx($img_r) / $img_w;
         $y = $y * imagesy($img_r) / $img_h;
         $w = $w * imagesx($img_r) / $img_w;
         $h = $h * imagesy($img_r) / $img_h;
         $dst_r = imageCreateTrueColor($this->target_width, $this->target_height);
         imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $this->target_width, $this->target_height, $w, $h);
         imagejpeg($dst_r, $this->avatarfile, $this->jpeg_quality);
         $dst_r = imageCreateTrueColor($this->mini_width, $this->mini_height);
         imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $this->mini_width, $this->mini_height, $w, $h);
         imagejpeg($dst_r, $this->minifile, $this->jpeg_quality);
         Activity::fireUpdateAvatar();
         $this->ajaxReturn(array('result' => 'success'));
     } catch (Exception $e) {
         $this->ajaxReturn(array('result' => 'failure', 'message' => $e->getMessage()));
     }
 }
예제 #8
0
파일: Image.php 프로젝트: ootori/aulait
 /**
  * @param int $maxX
  * @param int $maxY
  * @param bool $ignoreAspectRatio 画像の縦横比を維持するか。
  * @return Image
  */
 public function resize($maxX = 180, $maxY = 180, $ignoreAspectRatio = false)
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     if ($ignoreAspectRatio === false) {
         $resizeX = $maxX;
         $resizeY = $maxY;
     } elseif ($width < $height) {
         $resizeX = ceil($maxX * $width / $height);
         $resizeY = $maxY;
     } else {
         $resizeX = $maxX;
         $resizeY = ceil($maxY * $height / $width);
     }
     // 透明色が指定されているとjpg保存時に透明色部が黒くなるのでその対策。
     // MEMO: PNGで保存するなら
     //       imagealphablending($resize, false);
     //       imagesavealpha($resize, true);
     $resizeGD = @imageCreateTrueColor($resizeX, $resizeY);
     $alpha = imagecolortransparent($this->gd);
     if ($alpha !== -1) {
         $color = imagecolorallocate($resizeGD, 255, 255, 255);
         imageFill($resizeGD, 0, 0, $color);
         imageColorTransparent($resizeGD, $alpha);
     } else {
         imageAlphaBlending($resizeGD, true);
         imageSaveAlpha($resizeGD, true);
         $fill_color = imagecolorallocate($resizeGD, 255, 255, 255);
         imageFill($resizeGD, 0, 0, $fill_color);
     }
     imageCopyResampled($resizeGD, $this->gd, 0, 0, 0, 0, $resizeX, $resizeY, $width, $height);
     return new Image($resizeGD);
 }
예제 #9
0
 private function createImage($width = 100, $height = 100)
 {
     $dest = imageCreateTrueColor($width, $height);
     // antialising funktion zum glätten verkleinerter grafiken
     // funktioniert aus unerfindlichen gründen nicht
     //imageantialias($dest, TRUE);
     return $dest;
 }
예제 #10
0
function create_thumb($path, $thumb_path, $width = THUMB_WIDTH, $height = THUMB_HEIGHT)
{
    $image_info = getImageSize($path);
    // see EXIF for faster way
    switch ($image_info['mime']) {
        case 'image/gif':
            if (imagetypes() & IMG_GIF) {
                // not the same as IMAGETYPE
                $o_im = @imageCreateFromGIF($path);
            } else {
                throw new Exception('GIF images are not supported');
            }
            break;
        case 'image/jpeg':
            if (imagetypes() & IMG_JPG) {
                $o_im = @imageCreateFromJPEG($path);
            } else {
                throw new Exception('JPEG images are not supported');
            }
            break;
        case 'image/png':
            if (imagetypes() & IMG_PNG) {
                $o_im = @imageCreateFromPNG($path);
            } else {
                throw new Exception('PNG images are not supported');
            }
            break;
        case 'image/wbmp':
            if (imagetypes() & IMG_WBMP) {
                $o_im = @imageCreateFromWBMP($path);
            } else {
                throw new Exception('WBMP images are not supported');
            }
            break;
        default:
            throw new Exception($image_info['mime'] . ' images are not supported');
            break;
    }
    list($o_wd, $o_ht, $html_dimension_string) = $image_info;
    $ratio = $o_wd / $o_ht;
    $t_ht = $width;
    $t_wd = $height;
    if (1 > $ratio) {
        $t_wd = round($o_wd * $t_wd / $o_ht);
    } else {
        $t_ht = round($o_ht * $t_ht / $o_wd);
    }
    $t_wd = $t_wd < 1 ? 1 : $t_wd;
    $t_ht = $t_ht < 1 ? 1 : $t_ht;
    $t_im = imageCreateTrueColor($t_wd, $t_ht);
    imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
    imagejpeg($t_im, $thumb_path, 85);
    chmod($thumb_path, 0664);
    imageDestroy($o_im);
    imageDestroy($t_im);
    return array($t_wd, $t_ht);
}
 /**
  * @param string $name
  * @param int    $colorScheme
  * @param int    $backgroundStyle
  *
  * @return $this
  */
 public function generate($name, $colorScheme, $backgroundStyle = null)
 {
     $name = strtoupper(substr($name, 0, $this->chars));
     $bgColor = $this->colorSchemes[$colorScheme];
     $this->avatar = imageCreateTrueColor($this->width, $this->height);
     imageFill($this->avatar, 0, 0, $bgColor);
     $this->drawString($name, 0xffffff);
     return $this;
 }
예제 #12
0
function generate_thumbnail($file, $mime)
{
    global $config;
    gd_capabilities();
    list($file_type, $exact_type) = explode("/", $mime);
    if (_JB_GD_INSTALLED && ($file_type = "image")) {
        if ($exact_type != "gif" && $exact_type != "png" && $exact_type != "jpeg") {
            return false;
        }
        if ($exact_type == "gif" && !_JB_GD_GIF) {
            return false;
        }
        if ($exact_type == "png" && !_JB_GD_PNG) {
            return false;
        }
        if ($exact_type == "jpeg" && !_JB_GD_JPG) {
            return false;
        }
        // Load up the original and get size
        //  NOTE: use imageCreateFromString to avoid to have to check what type of image it is
        $original = imageCreateFromString(file_get_contents($file));
        $original_w = imagesX($original);
        $original_h = imagesY($original);
        // Only if the image is really too big, resize it
        // NOTE: if image is smaller than target size, don't do anything.
        //  We *could* copy the original to filename_thumb, but since it's the same
        //  it would be a waste of precious resources
        if ($original_w > $config['uploader']['thumb_w'] || $original_h > $config['uploader']['thumb_h']) {
            // If original is wider than it's high, resize the width and vice versa
            // NOTE: '>=' cause otherwise it's possible that $scale isn't computed
            if ($original_w >= $original_h) {
                $scaled_w = $config['uploader']['thumb_w'];
                // Figure out how much smaller that target is than original
                //  and apply it to height
                $scale = $config['uploader']['thumb_w'] / $original_w;
                $scaled_h = ceil($original_h * $scale);
            } elseif ($original_w <= $original_h) {
                $scaled_h = $config['uploader']['thumb_h'];
                $scale = $config['uploader']['thumb_h'] / $original_h;
                $scaled_w = ceil($original_w * $scale);
            }
        } else {
            // Break out of if($file_type = image) since no resize is possible
            return false;
        }
        // Scale the image
        $scaled = imageCreateTrueColor($scaled_w, $scaled_h);
        imageCopyResampled($scaled, $original, 0, 0, 0, 0, $scaled_w, $scaled_h, $original_w, $original_h);
        // Store thumbs in jpeg, hope no one minds the 100% quality lol
        imageJpeg($scaled, $file . "_thumb", 100);
        // Let's be nice to our server
        imagedestroy($scaled);
        imagedestroy($original);
        return true;
    }
}
예제 #13
0
 public function setUp()
 {
     if (!extension_loaded('gd')) {
         $this->markTestSkipped('The GD extension is not available.');
         return;
     }
     $this->factory = ImageFactory::getInstance();
     $this->mockExtension = 'mock';
     $this->mockResource = imageCreateTrueColor(50, 50);
 }
 /**
  * @param string $name
  * @param int    $colorScheme
  * @param int    $backgroundStyle
  *
  * @return $this
  */
 public function generate($name, $colorScheme, $backgroundStyle)
 {
     list($bgColor1, $bgColor2, $textColor) = $this->colorSchemes[$colorScheme];
     $this->avatar = imageCreateTrueColor($this->width, $this->height);
     imageFill($this->avatar, 0, 0, $bgColor1);
     $this->drawBG($bgColor2, $backgroundStyle);
     $this->drawString($name, $textColor);
     $this->copyOverlay();
     return $this;
 }
예제 #15
0
 /**
  * Draws the pie chart, with optional supersampled anti-aliasing.
  * @param int $aa
  */
 public function draw($aa = 4)
 {
     $this->canvas = imageCreateTrueColor($this->width, $this->height);
     // Set anti-aliasing for the pie chart.
     imageAntiAlias($this->canvas, true);
     imageFilledRectangle($this->canvas, 0, 0, $this->width, $this->height, $this->_convertColor($this->backgroundColor));
     $total = 0;
     $sliceStart = -90;
     // Start at 12 o'clock.
     $titleHeight = $this->_drawTitle();
     $legendWidth = $this->_drawLegend($titleHeight);
     // Account for the space occupied by the legend and its padding.
     $pieCentreX = ($this->width - $legendWidth) / 2;
     // Account for the space occupied by the title.
     $pieCentreY = $titleHeight + ($this->height - $titleHeight) / 2;
     // 10% padding on the top and bottom of the pie.
     $pieDiameter = round(min($this->width - $legendWidth, $this->height - $titleHeight) * 0.85);
     foreach ($this->slices as $slice) {
         $total += $slice['value'];
     }
     // If anti-aliasing is enabled, we supersample the pie to work around
     // the fact that GD does not provide anti-aliasing natively.
     if ($aa > 0) {
         $ssDiameter = $pieDiameter * $aa;
         $ssCentreX = $ssCentreY = $ssDiameter / 2;
         $superSample = imageCreateTrueColor($ssDiameter, $ssDiameter);
         imageFilledRectangle($superSample, 0, 0, $ssDiameter, $ssDiameter, $this->_convertColor($this->backgroundColor));
         foreach ($this->slices as $slice) {
             $sliceWidth = 360 * $slice['value'] / $total;
             // Skip slices that are too small to draw / be visible.
             if ($sliceWidth == 0) {
                 continue;
             }
             $sliceEnd = $sliceStart + $sliceWidth;
             imageFilledArc($superSample, $ssCentreX, $ssCentreY, $ssDiameter, $ssDiameter, $sliceStart, $sliceEnd, $this->_convertColor($slice['color']), IMG_ARC_PIE);
             // Move along to the next slice.
             $sliceStart = $sliceEnd;
         }
         imageCopyResampled($this->canvas, $superSample, $pieCentreX - $pieDiameter / 2, $pieCentreY - $pieDiameter / 2, 0, 0, $pieDiameter, $pieDiameter, $ssDiameter, $ssDiameter);
         imageDestroy($superSample);
     } else {
         // Draw the slices.
         foreach ($this->slices as $slice) {
             $sliceWidth = 360 * $slice['value'] / $total;
             // Skip slices that are too small to draw / be visible.
             if ($sliceWidth == 0) {
                 continue;
             }
             $sliceEnd = $sliceStart + $sliceWidth;
             imageFilledArc($this->canvas, $pieCentreX, $pieCentreY, $pieDiameter, $pieDiameter, $sliceStart, $sliceEnd, $this->_convertColor($slice['color']), IMG_ARC_PIE);
             // Move along to the next slice.
             $sliceStart = $sliceEnd;
         }
     }
 }
예제 #16
0
 private function _createBg()
 {
     // 画布的宽度和高度为对象的$width和$height属性值
     $img = imageCreateTrueColor($this->width, $this->height);
     // p($img);die;
     // 把十六进制颜色转化为函数可以使用的RGB颜色
     $color = hexdec($this->bgColor);
     // 画布底色填充为全部,颜色来自于$color
     imagefill($img, 0, 0, $color);
     // 把生成好的画布赋给对象的$img属性
     $this->img = $img;
 }
예제 #17
0
 public function testWriteThrowsExceptionWhenFileIsNotWritable()
 {
     $this->runByRootUserSkipsTest();
     try {
         $this->io->write(new File('/etc/test.gif'), imageCreateTrueColor(100, 100));
     } catch (ImageException $e) {
         return;
     } catch (FileSystemException $e) {
         return;
     }
     $this->fail();
 }
예제 #18
0
function image_create_thumb($img_file_path, $thumb_file_path, $width, $height)
{
    if (($image = _image_load($img_file_path)) === false) {
        return false;
    }
    $src_x = 0;
    $src_y = 0;
    $src_w = 0;
    $src_h = 0;
    $dst_w = 0;
    $dst_h = 0;
    _image_calculate_dimensions(imagesx($image), imagesy($image), $width, $height, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h);
    //die('initial image width is ' . $original_width . ', requested width is ' . $width . ', new image width is ' . $new_img_width . ', src_x is ' . $src_x);
    $thumb_image = imageCreateTrueColor($dst_w, $dst_h);
    imageCopyResampled($thumb_image, $image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    return _image_save($thumb_file_path, $thumb_image);
}
예제 #19
0
 public function createThumbs($thumb_size)
 {
     $thumb = imageCreateTrueColor($thumb_size['width'], $thumb_size['height']);
     if ($thumb === false) {
         throw new Exception('cannot create img_thumb file');
     }
     $resX = floor(imagesx($this->_orig_img) * ($thumb_size['height'] / imagesy($this->_orig_img)));
     $resY = $thumb_size['height'];
     imageAntiAlias($thumb, true);
     imagecopyresized($thumb, $this->_orig_img, 0, 0, 0, 0, $resX, $resY, imagesx($this->_orig_img), imagesy($this->_orig_img));
     if (!imageJPEG($thumb, $this->_save_path . 'thumbs_' . $this->_new_img_name, 100)) {
         imagedestroy($thumb);
         throw new Exception('cannot save img_thumbs file');
     }
     imagedestroy($thumb);
     return $this;
 }
예제 #20
0
 /**
  * Constructor: mxGdCanvas
  *
  * Constructs a new GD canvas. Use a HTML color definition for
  * the optional background parameter, eg. white or #FFFFFF.
  * The buffered <image> is only created if the given
  * width and height are greater than 0.
  */
 function mxGdCanvas($width = 0, $height = 0, $scale = 1, $background = null, $imageBasePath = "")
 {
     $this->enableTtf = mxConstants::$TTF_ENABLED;
     $this->imageBasePath = $imageBasePath;
     $this->scale = $scale;
     if ($width > 0 && $height > 0) {
         $this->image = @imageCreateTrueColor($width, $height);
         if ($this->antialias && function_exists("imageantialias")) {
             imageantialias($this->image, true);
         }
         if (isset($background)) {
             $color = $this->getColor($background);
             imageFilledRectangle($this->image, 0, 0, $width, $height, $color);
         }
         $this->shadowColor = $this->getColor(mxConstants::$W3C_SHADOWCOLOR);
     }
 }
예제 #21
0
 function AnimatedOut()
 {
     for ($i = 0; $i < ANIM_FRAMES; $i++) {
         $image = imageCreateTrueColor(imageSX($this->image), imageSY($this->image));
         if (imageCopy($image, $this->image, 0, 0, 0, 0, imageSX($this->image), imageSY($this->image))) {
             Captcha::DoNoise($image, 200, 0);
             Ob_Start();
             imageGif($image);
             imageDestroy($image);
             $f_arr[] = Ob_Get_Contents();
             $d_arr[] = ANIM_DELAYS;
             Ob_End_Clean();
         }
     }
     $GIF = new GIFEncoder($f_arr, $d_arr, 0, 2, -1, -1, -1, 'C_MEMORY');
     return $GIF->GetAnimation();
 }
예제 #22
0
 function resizeImage($filename, $new_width = 0, $new_height = 0)
 {
     if (file_exists($filename)) {
         $lst = GetImageSize($filename);
         $image_width = $lst[0];
         $image_height = $lst[1];
         $image_format = $lst[2];
         $type = 0;
         switch ($type) {
             case 0:
                 if ($new_width != 0 && $new_width < $image_width) {
                     $image_height = (int) ($image_height * ($new_width / $image_width));
                     $image_width = $new_width;
                 }
                 if ($new_height != 0 && $new_height < $image_height) {
                     $image_width = (int) ($image_width * ($new_height / $image_height));
                     $image_height = $new_height;
                 }
                 break;
             case 1:
                 $image_width = $new_width;
                 $image_height = $image_height;
                 break;
         }
         if ($image_format == 1) {
             $old_image = imagecreatefromgif($filename);
         } elseif ($image_format == 2) {
             $old_image = imagecreatefromjpeg($filename);
         } elseif ($image_format == 3) {
             $old_image = imagecreatefrompng($filename);
         } else {
             return 0;
         }
         $new_image = imageCreateTrueColor($image_width, $image_height);
         $white = ImageColorAllocate($new_image, 255, 255, 255);
         ImageFill($new_image, 0, 0, $white);
         /*imageCopyResized*/
         imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $image_width, $image_height, imageSX($old_image), imageSY($old_image));
         //   Save to file
         imageJpeg($new_image, $filename);
         return 1;
     } else {
         return 0;
     }
 }
예제 #23
0
function textToImg($text, $backRGB, $strRGB, $fontPath, $fontSize, $margin)
{
    // 大きさを測定
    $result = imageTTFBBox($fontSize, 0, $fontPath, $text);
    // 幅と高さを取得
    $width = abs($result[4]) + abs($result[6]) + $margin * 2;
    $height = abs($result[1]) + abs($result[7]) + $margin * 2;
    // イメージリソースを生成
    $img = imageCreateTrueColor($width, $height);
    // 色を生成
    $backColor = imageColorAllocate($img, $backRGB['red'], $backRGB['green'], $backRGB['blue']);
    $strColor = imageColorAllocate($img, $strRGB['red'], $strRGB['green'], $strRGB['blue']);
    // 背景を塗りつぶす
    imageFilledRectangle($img, 0, 0, $width, $height, $backColor);
    // 文字を描く
    imageTTFText($img, $fontSize, 0, $margin + abs($result[0]), $margin + abs($result[7]), $strColor, $fontPath, $text);
    return $img;
}
예제 #24
0
 function resize($width = 400, $height = 400, $aspectradio = true)
 {
     $o_wd = imagesx($this->image);
     $o_ht = imagesy($this->image);
     if (isset($aspectradio) && $aspectradio) {
         $w = round($o_wd * $height / $o_ht);
         $h = round($o_ht * $width / $o_wd);
         if ($height - $h < $width - $w) {
             $width =& $w;
         } else {
             $height =& $h;
         }
     }
     $this->temp = imageCreateTrueColor($width, $height);
     imageCopyResampled($this->temp, $this->image, 0, 0, 0, 0, $width, $height, $o_wd, $o_ht);
     $this->sync();
     return;
 }
예제 #25
0
function resizeToSquare($src, $dest, $edge, $quality = 80)
{
    if (file_exists($src) && isset($dest)) {
        // image src size
        $srcSize = getImageSize($src);
        $srcRatio = $srcSize[0] / $srcSize[1];
        // width/height ratio
        if ($srcRatio >= 1) {
            $destSize[1] = $edge;
            //smallest side becomes $edge
            $destSize[0] = $edge * $srcRatio;
            //other side is enlarged
        } else {
            $destSize[0] = $edge;
            //smallest side becomse $edge
            $destSize[1] = $edge / $srcRatio;
            //other side is enlarged
        }
        // true color image, with anti-aliasing
        $destImage = imageCreateTrueColor($edge, $edge);
        // src image
        $srcImage = imageCreateFromJpeg($src);
        // resampling
        if ($srcRatio >= 1) {
            //when width>height : cut of piece left and right
            imageCopyResampled($destImage, $srcImage, -($destSize[0] - $edge) / 2, 0, 0, 0, $destSize[0], $destSize[1], $srcSize[0], $srcSize[1]);
        } else {
            //when width<height : cut of a piece on top and bottom
            imageCopyResampled($destImage, $srcImage, 0, -($destSize[1] - $edge) / 2, 0, 0, $destSize[0], $destSize[1], $srcSize[0], $srcSize[1]);
        }
        // generating image
        imageJpeg($destImage, $dest, $quality);
        imagedestroy($destImage);
        imagedestroy($srcImage);
        return true;
    } else {
        return false;
    }
}
예제 #26
0
function resizeImage($file, $max_x, $max_y, $forcePng = false)
{
    if ($max_x <= 0 || $max_y <= 0) {
        $max_x = 5;
        $max_y = 5;
    }
    $src = BASEDIR . '/avatars/' . $file;
    list($width, $height, $type) = getImageSize($src);
    $scale = min($max_x / $width, $max_y / $height);
    $newWidth = $width * $scale;
    $newHeight = $height * $scale;
    $img = imagecreatefromstring(file_get_contents($src));
    $black = imagecolorallocate($img, 0, 0, 0);
    $resizedImage = imageCreateTrueColor($newWidth, $newHeight);
    imagecolortransparent($resizedImage, $black);
    imageCopyResampled($resizedImage, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
    imageDestroy($img);
    unlink($src);
    if (!$forcePng) {
        switch ($type) {
            case IMAGETYPE_JPEG:
                imageJpeg($resizedImage, BASEDIR . '/avatars/' . $file);
                break;
            case IMAGETYPE_GIF:
                imageGif($resizedImage, BASEDIR . '/avatars/' . $file);
                break;
            case IMAGETYPE_PNG:
                imagePng($resizedImage, BASEDIR . '/avatars/' . $file);
                break;
            default:
                imagePng($resizedImage, BASEDIR . '/avatars/' . $file);
                break;
        }
    } else {
        imagePng($resizedImage, BASEDIR . '/avatars/' . $file . '.png');
    }
    return;
}
 function Cartoonfy($p_image, $p_triplevel, $p_diffspace)
 {
     $this->triplevel = (int) (2000.0 + 5000.0 * $p_triplevel);
     $this->diffspace = (int) ($p_diffspace * 32.0);
     $this->i0 = imageCreateFromString(file_get_contents($p_image));
     if ($this->i0) {
         $this->i1 = imageCreateTrueColor(imageSx($this->i0), imageSy($this->i0));
         for ($x = (int) $this->diffspace; $x < imageSx($this->i0) - (1 + (int) $this->diffspace); $x++) {
             for ($y = (int) $this->diffspace; $y < imageSy($this->i0) - (1 + (int) $this->diffspace); $y++) {
                 $t = Cartoonfy::GetMaxContrast($x, $y);
                 if ($t > $this->triplevel) {
                     imageSetPixel($this->i1, $x, $y, 0);
                 } else {
                     imageSetPixel($this->i1, $x, $y, Cartoonfy::FlattenColor(imageColorAt($this->i0, $x, $y)));
                 }
             }
             //usleep(1000);
         }
         imageDestroy($this->i0);
     } else {
         print "<b>" . $p_image . "</b> is not supported image format!";
         exit;
     }
 }
예제 #28
0
 /** 
  * Shows an image, possibly resized in the desired... size!
  *
  * Call it like: localhost/index.php?r=images/show&src=images/boats/3/boat.jpg&width=100
  * If only one dimension is given, aspect ratio is maintained.
  * If both dimensions are given, and are far from aspect ratio, 
  * the action tries to return a meaningful portion of the image.
  */
 public function show($src = '', $width = '', $height = '')
 {
     // sometime in the future, we should cache the result of the resize to make it fast.
     // we do not check for "is_file", because sometimes we are asked to resize remote images.
     //if (!is_file($src))
     //	throw new CHttpException(404);
     // if nothing given, simply redirect to the file.
     if ($width == '' && $height == '' || $width == 0 && $height == 0) {
         $this->_send_headers($src);
         header('Location: ' . $src);
         Yii::app()->end();
     }
     // we need to resize..
     if (!($source_image = $this->_img_load($src))) {
         throw new CHttpException(500);
     }
     $original_width = imagesx($source_image);
     $original_height = imagesy($source_image);
     $requested_width = $width;
     $requested_height = $height;
     $src_x = 0;
     $src_y = 0;
     $dst_x = 0;
     $dst_y = 0;
     $src_w = 0;
     $src_h = 0;
     $dst_w = 0;
     $dst_h = 0;
     $this->_calculate_dimensions($original_width, $original_height, $requested_width, $requested_height, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h);
     //die('initial image width is ' . $original_width . ', requested width is ' . $width . ', new image width is ' . $new_img_width . ', src_x is ' . $src_x);
     $target_image = imageCreateTrueColor($dst_w, $dst_h);
     imageCopyResampled($target_image, $source_image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
     // send it.
     $this->_send_headers($src);
     $this->_img_send($target_image, $src);
 }
 function imagecopyresampled_adv($image_type, &$dest, $source, $d_x, $d_y, $s_x, $s_y, $d_w, $d_h, $s_w, $s_h)
 {
     switch ($image_type) {
         // Process GIF images
         case 1:
             $transcol = imagecolortransparent($source);
             $dest = imagecreate($d_w, $d_h);
             imagepalettecopy($dest, $source);
             imagefill($dest, 0, 0, $transcol);
             imagecolortransparent($dest, $transcol);
             return imagecopyresized($dest, $source, $d_x, $d_y, $s_x, $s_y, $d_w, $d_h, $s_w, $s_h);
             break;
             // Process PNG images
         // Process PNG images
         case 3:
             $dest = imageCreateTrueColor($d_w, $d_h);
             imagealphablending($dest, false);
             imagesavealpha($dest, true);
             $transparent = imagecolorallocatealpha($dest, 255, 255, 255, 0);
             //BOF - DokuMan - 2011-01-06 - imagecolortransparent much faster on big images
             //for ($x = 0; $x < $d_w; $x++) {
             //  for ($y = 0; $y < $d_h; $y++) {
             //    imageSetPixel($dest, $x, $y, $transparent);
             //  }
             //}
             imagecolortransparent($dest, $transparent);
             //EOF - DokuMan - 2011-01-06 - imagecolortransparent much faster on big images
             return imagecopyresampled($dest, $source, $d_x, $d_y, $s_x, $s_y, $d_w, $d_h, $s_w, $s_h);
             break;
             // Any other images
         // Any other images
         default:
             $dest = imageCreateTrueColor($d_w, $d_h);
             return imagecopyresampled($dest, $source, $d_x, $d_y, $s_x, $s_y, $d_w, $d_h, $s_w, $s_h);
     }
 }
 public function generate($name, $colorScheme, $backgroundStyle)
 {
     list($bgColor1, $bgColor2, $textColor) = self::$colorSchemes[$colorScheme];
     $this->avatar = imageCreateTrueColor($this->width, $this->height);
     imageFill($this->avatar, 0, 0, $bgColor1);
     // Draw some random chars into the background. Unlike the other GD drawing functions
     // (imageFilledArc, imageFilledPolygon etc.) imageTTFText is anti-aliased.
     $sizeFactor = $this->width / 40;
     switch ($backgroundStyle) {
         case 0:
             imageTTFText($this->avatar, 190 * $sizeFactor, 10, 0, 35 * $sizeFactor, $bgColor2, $this->fontFace, 'O');
             break;
         case 1:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 45 * $sizeFactor, $bgColor2, $this->fontFace, 'o');
             break;
         case 2:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 30 * $sizeFactor, $bgColor2, $this->fontFace, '>');
             break;
         case 3:
             imageTTFText($this->avatar, 90 * $sizeFactor, 0, -30 * $sizeFactor, 45 * $sizeFactor, $bgColor2, $this->fontFace, '//');
             break;
     }
     // Draw the first few chars of the name
     imageTTFText($this->avatar, $this->fontSize, 0, 4, $this->height - $this->fontSize / 2, $textColor, $this->fontFace, mb_substr($name, 0, $this->chars));
     // Copy the overlay on top
     if ($this->overlay) {
         imageCopy($this->avatar, $this->overlay, 0, 0, 0, 0, imageSX($this->overlay), imageSY($this->overlay));
     }
 }