Exemple #1
0
 /**
  * Get the image in a specific format
  * @param  string|null $format        optional format to get the image in, if null the source image format is used
  * @return string binary string of the converted image
  */
 public function getImage(string $format = null) : string
 {
     if (!$format) {
         $format = explode('/', $this->info['mime'], 2)[1];
     }
     switch (strtolower($format)) {
         case 'jpg':
         case 'jpeg':
             ob_start();
             imagejpeg($this->data);
             return ob_get_clean();
         case 'bitmap':
         case 'bmp':
             ob_start();
             imagewbmp($this->data);
             return ob_get_clean();
         case 'png':
             ob_start();
             imagepng($this->data);
             return ob_get_clean();
         case 'gif':
             ob_start();
             imagegif($this->data);
             return ob_get_clean();
         case 'webp':
             ob_start();
             imagewebp($this->data, null);
             return ob_get_clean();
         default:
             throw new ImageException('Unsupported format');
     }
 }
Exemple #2
0
 function display()
 {
     ob_end_flush();
     ob_start();
     switch (strtolower($this->format)) {
         case 'jpeg':
         case 'jpg':
             imagejpeg($this->data);
             break;
         case 'gif':
             imagegif($this->data);
             break;
         case 'png':
             imagepng($this->data);
             break;
         case 'wbmp':
             imagewbmp($this->data);
             break;
         default:
             ob_end_clean();
             return NULL;
     }
     $image = ob_get_contents();
     ob_end_clean();
     return $image;
 }
Exemple #3
0
 public function genFile($fileName, $quality = 100)
 {
     $image = parent::returnThumbnail();
     $result = false;
     if (!empty($image)) {
         switch ($this->image_type) {
             case 1:
                 $result = imagegif($image, $fileName);
                 break;
             case 2:
                 $quality = (int) $quality;
                 if ($quality < 0 || $quality > 100) {
                     $quality = 75;
                 }
                 // end if
                 $result = imagejpeg($image, $fileName, $quality);
                 break;
             case 3:
                 $result = imagepng($image, $fileName);
                 break;
             case 15:
                 $result = imagewbmp($image, $fileName);
                 break;
         }
         // end switch
     }
     return $result;
 }
Exemple #4
0
 public function index($image_id)
 {
     $result = mysqli_fetch_array($this->db->db_query("SELECT `Image` FROM `Restaurant_Images` where `idRestaurant_Images` = '{$image_id}'"));
     $uri = 'data://application/octet-stream;base64,' . base64_encode($result['Image']);
     $image_type = getimagesize($uri);
     if ($result !== NULL) {
         header('Content-Type: ', $image_type['mime']);
         $image = imagecreatefromstring($result['Image']);
         switch ($image_type['mime']) {
             case 'image/jpeg':
                 imagejpeg($image);
                 break;
             case 'image/bmp':
                 imagewbmp($image);
                 break;
             case 'image/gif':
                 imagegif($image);
                 break;
             case 'image/png':
                 imagepng($image);
                 break;
             default:
                 echo "Unsupported picture type: " . $image_type;
                 return;
         }
         imagedestroy($image);
     } else {
         header('Content-Type: image/png');
         $fp = fopen(APP_ROOT . '/img/restaurant.png', 'r');
         fpassthru($fp);
     }
 }
Exemple #5
0
 /**
  * @brief 生成图片文件
  * @param resource $imageRes      图片资源名称
  * @param string   $thumbFileName 缩略图名称
  * @param bool     $imageResult   生成缩略图状态 true:成功; false:失败;
  */
 public static function createImageFile($imageRes, $thumbFileName)
 {
     //如果目录不可写直接返回,防止错误抛出
     if (!is_writeable(dirname($thumbFileName))) {
         return false;
     }
     $imageResult = false;
     //获取文件扩展名
     $fileExt = IFile::getFileSuffix($thumbFileName);
     switch ($fileExt) {
         case 'jpg':
         case 'jpeg':
             $imageResult = imagejpeg($imageRes, $thumbFileName, 100);
             break;
         case 'gif':
             $imageResult = imagegif($imageRes, $thumbFileName);
             break;
         case 'png':
             $imageResult = imagepng($imageRes, $thumbFileName);
             break;
         case 'bmp':
             $imageResult = imagewbmp($imageRes, $thumbFileName);
             break;
     }
     return $imageResult;
 }
function resize($filename, $size, $quality)
{
    $dir = UPLOADDIR;
    // Адрес директории для сохранения картинки
    $ext = strtolower(strrchr(basename($filename), "."));
    // Получаем формат уменьшаемого изображения
    $extentions = array('.jpg', '.gif', '.png', '.bmp');
    // Определяем формат уменьшаемой картинки
    if (in_array($ext, $extentions)) {
        echo '01';
        $percent = $size;
        // Ширина изображения миниатюры
        list($width, $height) = getimagesize(UPLOADDIR . $filename);
        // Возвращает ширину и высоту картинки
        $newheight = $height * $percent;
        $newwidth = $newheight / $width;
        $thumb = imagecreatetruecolor($percent, $newwidth);
        switch ($ext) {
            case '.jpg':
                $source = @imagecreatefromjpeg(UPLOADDIR . $filename);
                break;
            case '.gif':
                $source = @imagecreatefromgif(UPLOADDIR . $filename);
                break;
            case '.png':
                $source = @imagecreatefrompng(UPLOADDIR . $filename);
                break;
            case '.bmp':
                $source = @imagecreatefromwbmp(UPLOADDIR . $filename);
                break;
        }
        // php уменьшение изображения
        imagecopyresized($thumb, $source, 0, 0, 0, 0, $percent, $newwidth, $width, $height);
        // Создаем изображение
        switch ($ext) {
            case '.jpg':
                imagejpeg($thumb, UPLOADDIR . "min_" . $filename, $quality);
                // Для JPEG картинок
                break;
            case '.gif':
                imagegif($thumb, UPLOADDIR . $filename);
                // Для GIF картинки
                break;
            case '.png':
                imagepng($thumb, UPLOADDIR . $filename, $quality);
                // Для PNG картинок
                break;
            case '.bmp':
                imagewbmp($thumb, UPLOADDIR . $filename);
                // Для BMP картинки
                break;
        }
    } else {
        return 'typeError';
    }
    @imagedestroy($thumb);
    @imagedestroy($source);
    return $filename;
}
Exemple #7
0
/**
 * Make a thumbnail of a newly uploaded file if it is an image
 *
 * @param $src the source of the file
 * @param $dest where to save the thumbnail
 * @param $fileExt the file extension (to check if the file is an image)
 * @param $desired_width the desired width of the thumbnail, height and width are kept in ratio
 */
function make_thumb($src, $dest, $fileExt, $desired_width)
{
    $exif = exif_read_data($src, 'IFD0');
    // Read the source image
    if ($fileExt == 'gif') {
        $source_image = imagecreatefromgif($src);
    } elseif ($fileExt == 'jpg' || $fileExt == 'jpeg') {
        $source_image = imagecreatefromjpeg($src);
    } elseif ($fileExt == 'png') {
        $source_image = imagecreatefrompng($src);
    } elseif ($fileExt == 'wbmp') {
        $source_image = imagecreatefromwbmp($src);
    } else {
        // Return if not an image
        return;
    }
    // Fix Orientation of original image - this has to be done because of stupid apple products who can't save their
    // orientation like everybody else, ugh!
    switch ($exif['Orientation']) {
        case 3:
            $source_image = imagerotate($source_image, 180, 0);
            break;
        case 6:
            $source_image = imagerotate($source_image, -90, 0);
            break;
        case 8:
            $source_image = imagerotate($source_image, 90, 0);
            break;
    }
    // Save turned source image again (overwrites false orientation)
    if ($fileExt == 'gif') {
        imagegif($source_image, $src);
    } elseif ($fileExt == 'jpg' || $fileExt == 'jpeg') {
        imagejpeg($source_image, $src);
    } elseif ($fileExt == 'png') {
        imagepng($source_image, $src);
    } elseif ($fileExt == 'bmp') {
        imagewbmp($source_image, $src);
    }
    $width = imagesx($source_image);
    $height = imagesy($source_image);
    // Find the "desired height" of this thumbnail, relative to the desired width
    $desired_height = floor($height * ($desired_width / $width));
    // Create a new, "virtual" image
    $virtual_image = imagecreatetruecolor($desired_width, $desired_height);
    // Copy source image at a resized size
    imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
    // Create the physical thumbnail image to its destination
    if ($fileExt == 'gif') {
        imagegif($virtual_image, $dest);
    } elseif ($fileExt == 'jpg' || $fileExt == 'jpeg') {
        imagejpeg($virtual_image, $dest);
    } elseif ($fileExt == 'png') {
        imagepng($virtual_image, $dest);
    } elseif ($fileExt == 'bmp') {
        imagewbmp($virtual_image, $dest);
    }
}
Exemple #8
0
 public function create()
 {
     //набор символов
     $letters = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'q', 'j', 'k', 'm', 'n', 'p', 'z', 'x', 'y', 's', 'u', 't', '2', '4', '5', '6', '7', '8', '9', '%', '+', '@', '#', '=', '?');
     //цвета
     $colors = array('90', '110', '130', '150', '170', '190', '210');
     $src = imagecreatetruecolor($this->width, $this->height);
     //создаем изображение
     $fon = imagecolorallocate($src, 255, 255, 255);
     //создаем фон
     imagefill($src, 0, 0, $fon);
     //заливаем изображение фоном
     for ($i = 0; $i < $this->fon_let_amount; $i++) {
         //случайный цвет
         $color = imagecolorallocatealpha($src, rand(0, 255), rand(0, 255), rand(0, 255), 100);
         //случайный символ
         $letter = $letters[rand(0, sizeof($letters) - 1)];
         //случайный размер
         $size = rand($this->font_size - 2, $this->font_size + 2);
         imagettftext($src, $size, rand(0, 45), rand($this->width * 0.1, $this->width - $this->width * 0.1), rand($this->height * 0.2, $this->height), $color, $this->font, $letter);
     }
     $code = array();
     for ($i = 0; $i < $this->let_amount; $i++) {
         $color = imagecolorallocatealpha($src, $colors[rand(0, sizeof($colors) - 1)], $colors[rand(0, sizeof($colors) - 1)], $colors[rand(0, sizeof($colors) - 1)], rand(20, 40));
         $letter = $letters[rand(0, sizeof($letters) - 1)];
         $size = rand($this->font_size * 2 - 2, $this->font_size * 2 + 2);
         $x = ($i + 1) * $this->font_size + rand(1, 5);
         //даем каждому символу случайное смещение
         $y = $this->height * 2 / 3 + rand(0, 5);
         $code[] = $letter;
         //запоминаем код
         imagettftext($src, $size, rand(0, 15), $x, $y, $color, $this->font, $letter);
     }
     $code = implode('', $code);
     //переводим код в строку
     // Обработка вывода
     if (imagetypes() & IMG_JPG) {
         // для JPEG
         header('Content-Type: image/jpeg');
         imagejpeg($src, NULL, 100);
     } elseif (imagetypes() & IMG_PNG) {
         // для PNG
         header('Content-Type: image/png');
         imagepng($src);
     } elseif (imagetypes() & IMG_GIF) {
         // для GIF
         header('Content-Type: image/gif');
         imagegif($src);
     } elseif (imagetypes() & IMG_PNG) {
         // для WBMP
         header('Content-Type: image/vnd.wap.wbmp');
         imagewbmp($src);
     } else {
         imagedestroy($src);
         return;
     }
     Session::set_server_data(array('captcha' => $code));
 }
Exemple #9
0
 public function build($text = '', $showText = true, $fileName = null)
 {
     if (trim($text) <= ' ') {
         throw new exception('barCode::build - must be passed text to operate');
     }
     if (!($fileType = $this->outMode[$this->mode])) {
         throw new exception("barCode::build - unrecognized output format ({$this->mode})");
     }
     if (!function_exists("image{$this->mode}")) {
         throw new exception("barCode::build - unsupported output format ({$this->mode} - check phpinfo)");
     }
     $text = strtoupper($text);
     $dispText = "* {$text} *";
     $text = "*{$text}*";
     // adds start and stop chars
     $textLen = strlen($text);
     $barcodeWidth = $textLen * (7 * $this->bcThinWidth + 3 * $this->bcThickWidth) - $this->bcThinWidth;
     $im = imagecreate($barcodeWidth, $this->bcHeight);
     $black = imagecolorallocate($im, 0, 0, 0);
     $white = imagecolorallocate($im, 255, 255, 255);
     imagefill($im, 0, 0, $white);
     $xpos = 0;
     for ($idx = 0; $idx < $textLen; $idx++) {
         if (!($char = $text[$idx])) {
             $char = '-';
         }
         for ($ptr = 0; $ptr <= 8; $ptr++) {
             $elementWidth = $this->codeMap[$char][$ptr] ? $this->bcThickWidth : $this->bcThinWidth;
             if (($ptr + 1) % 2) {
                 imagefilledrectangle($im, $xpos, 0, $xpos + $elementWidth - 1, $this->bcHeight, $black);
             }
             $xpos += $elementWidth;
         }
         $xpos += $this->bcThinWidth;
     }
     if ($showText) {
         $pxWid = imagefontwidth($this->fontSize) * strlen($dispText) + 10;
         $pxHt = imagefontheight($this->fontSize) + 2;
         $bigCenter = $barcodeWidth / 2;
         $textCenter = $pxWid / 2;
         imagefilledrectangle($im, $bigCenter - $textCenter, $this->bcHeight - $pxHt, $bigCenter + $textCenter, $this->bcHeight, $white);
         imagestring($im, $this->fontSize, $bigCenter - $textCenter + 5, $this->bcHeight - $pxHt + 1, $dispText, $black);
     }
     if (!$fileName) {
         header("Content-type:  image/{$fileType}");
     }
     switch ($this->mode) {
         case 'gif':
             imagegif($im, $fileName);
         case 'png':
             imagepng($im, $fileName);
         case 'jpeg':
             imagejpeg($im, $fileName);
         case 'wbmp':
             imagewbmp($im, $fileName);
     }
     imagedestroy($im);
 }
Exemple #10
0
 /**
  * {@inheritdoc}
  */
 public function generate($output, $outputPath = null)
 {
     // WBMP foreground seem doesn't work...
     if (!is_null($this->foreground)) {
         imagewbmp($output, $outputPath, $this->foreground->getColor());
     } else {
         imagewbmp($output, $outputPath);
     }
 }
 public function cropAction(Request $request)
 {
     $imageId = $request->request->get('imageId');
     /* @var $galleryImage GalleryImage */
     $galleryImage = $this->getDoctrine()->getRepository('KarolineKroissGalleryBundle:GalleryImage')->findOneBy(['id' => $imageId]);
     $targetWidth = 65;
     $targetHeight = 65;
     $quality = 100;
     $src = $galleryImage->getAbsolutePath();
     $src = $galleryImage->getUploadRootDir() . '/../../' . $galleryImage->getPreviewPath();
     $dst = $galleryImage->getUploadRootDir() . '/../../' . $galleryImage->getThumbnailPath();
     $type = strtolower(substr(strrchr($src, '.'), 1));
     if ($type == 'jpeg') {
         $type = 'jpg';
     }
     switch ($type) {
         case 'bmp':
             $imageResource = imagecreatefromwbmp($src);
             break;
         case 'gif':
             $imageResource = imagecreatefromgif($src);
             break;
         case 'jpg':
             $imageResource = imagecreatefromjpeg($src);
             break;
         case 'png':
             $imageResource = imagecreatefrompng($src);
             break;
         default:
             return 'Unsupported picture type!';
     }
     $destinationResource = imagecreatetruecolor($targetWidth, $targetHeight);
     imagecopyresampled($destinationResource, $imageResource, 0, 0, $request->request->get('x'), $request->request->get('y'), $targetWidth, $targetHeight, $request->request->get('w'), $request->request->get('h'));
     // preserve transparency
     if ($type == 'gif' or $type == 'png') {
         imagecolortransparent($destinationResource, imagecolorallocatealpha($destinationResource, 0, 0, 0, 127));
         imagealphablending($destinationResource, false);
         imagesavealpha($destinationResource, true);
     }
     switch ($type) {
         case 'bmp':
             imagewbmp($destinationResource, $dst);
             break;
         case 'gif':
             imagegif($destinationResource, $dst);
             break;
         case 'jpg':
             imagejpeg($destinationResource, $dst);
             break;
         case 'png':
             imagepng($destinationResource, $dst);
             break;
     }
     $request->headers->get('referer');
     return new RedirectResponse($request->headers->get('referer'));
 }
Exemple #12
0
/**
 * Converts image file contents to ZPL "download graphic" command
 *
 * @param string $in image binary string
 *
 * @param string $name arbitrary filename
 *
 * @return string ZPL "download graphic" command
 */
function wbmp_to_zpl($in, $name = '')
{
    if (empty($in)) {
        return '';
    }
    // Load image
    $im = imagecreatefromstring($in);
    if ($im === false) {
        return false;
    }
    // Black and white only
    imagefilter($im, IMG_FILTER_GRAYSCALE);
    //first, convert to grayscale
    imagefilter($im, IMG_FILTER_CONTRAST, -255);
    //then, apply a full contrast
    // Convert to WBMP
    ob_start();
    imagewbmp($im);
    $wbmp = ob_get_contents();
    ob_end_clean();
    $type = uintvar_shift($wbmp);
    $fixed = uintvar_shift($wbmp);
    $w = uintvar_shift($wbmp);
    $h = uintvar_shift($wbmp);
    $bitmap = ~$wbmp;
    // Black is white, white is black
    $total_bytes = strlen($bitmap);
    $bytes_per_line = ceil($w / 8);
    if ($w % 8 > 0) {
        // End of line is padded with black; make that white
        // Get last byte of each line
        $period = ceil($w / 8);
        for ($i = $bytes_per_line; $i <= $total_bytes; $i += $bytes_per_line) {
            $byte = ord($bitmap[$i - 1]);
            for ($j = 1; $j <= $w % 8; $j++) {
                // Flip j-th bit
                $byte = $byte & ~(1 << $j - 1);
            }
            $bitmap[$i - 1] = chr($byte);
        }
    }
    $uncompressed = strtoupper(bin2hex($bitmap));
    $compressed = preg_replace_callback('/(.)\\1{2,399}/', "zpl_rle_compress_helper", $uncompressed);
    $name = preg_replace('/[^A-z0-9]/', '', $name);
    if (strlen($name) > 8) {
        $name = substr($name, 0, 8);
    }
    $name = strtoupper($name);
    if (empty($name)) {
        $name = rand(10000000, 99999999);
    }
    $r = "~DG" . $name . ".GRF," . $total_bytes . "," . $bytes_per_line . "," . $compressed;
    return $r;
}
 function resizeImage($image, $width, $height, $scale)
 {
     $newImageWidth = ceil($width * $scale);
     $newImageHeight = ceil($height * $scale);
     $newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
     $ext = strtolower(substr(basename($image), strrpos(basename($image), ".") + 1));
     $source = "";
     if ($ext == 'jpeg') {
         $ext = 'jpg';
     }
     switch ($ext) {
         case 'bmp':
             $source = imagecreatefromwbmp($image);
             break;
         case 'gif':
             $source = imagecreatefromgif($image);
             break;
         case 'jpg':
             $source = imagecreatefromjpeg($image);
             break;
         case 'png':
             $source = imagecreatefrompng($image);
             break;
     }
     // preserve transparency
     if ($ext == "gif" or $ext == "png") {
         imagecolortransparent($source, imagecolorallocatealpha($source, 0, 0, 0, 127));
         imagealphablending($newImage, false);
         imagesavealpha($newImage, true);
     }
     imagecopyresampled($newImage, $source, 0, 0, 0, 0, $newImageWidth, $newImageHeight, $width, $height);
     imageinterlace($newImage, true);
     switch ($ext) {
         case 'bmp':
             imagewbmp($newImage, $image);
             break;
         case 'gif':
             imagegif($newImage, $image);
             break;
         case 'jpg':
             imagejpeg($newImage, $image, 100);
             break;
         case 'png':
             imagepng($newImage, $image, 0);
             break;
     }
     chmod($image, 0777);
     return $image;
 }
Exemple #14
0
 /**
  * 将图片资源保存到文件
  *
  * @param string $output      输出文件路径
  * @param string $outputType  输出类型, 默认为原图片类型
  * @return bool
  * @throws Exception
  */
 public function save($output, $outputType = '')
 {
     $outputType or $outputType = $this->mime;
     switch ($outputType) {
         case 'image/gif':
             return imagegif($this->resource, $output);
         case 'image/jpeg':
             return imagejpeg($this->resource, $output);
         case 'image/png':
             return imagepng($this->resource, $output);
         case 'image/bmp':
             return imagewbmp($this->resource, $output);
         default:
             throw new Exception("{$this->mime} type does not be image helper support");
     }
 }
Exemple #15
0
function ShowKey()
{
    $key = strtolower(domake_password(4));
    $set = esetcookie("checkkey", $key);
    //是否支持gd库
    if (function_exists("imagejpeg")) {
        header("Content-type: image/jpeg");
        $img = imagecreate(69, 20);
        $black = imagecolorallocate($img, 255, 255, 255);
        $gray = imagecolorallocate($img, 102, 102, 102);
        imagefill($img, 0, 0, $gray);
        imagestring($img, 3, 14, 3, $key, $black);
        imagejpeg($img);
        imagedestroy($img);
    } elseif (function_exists("imagegif")) {
        header("Content-type: image/gif");
        $img = imagecreate(69, 20);
        $black = imagecolorallocate($img, 255, 255, 255);
        $gray = imagecolorallocate($img, 102, 102, 102);
        imagefill($img, 0, 0, $gray);
        imagestring($img, 3, 14, 3, $key, $black);
        imagegif($img);
        imagedestroy($img);
    } elseif (function_exists("imagepng")) {
        header("Content-type: image/png");
        $img = imagecreate(69, 20);
        $black = imagecolorallocate($img, 255, 255, 255);
        $gray = imagecolorallocate($img, 102, 102, 102);
        imagefill($img, 0, 0, $gray);
        imagestring($img, 3, 14, 3, $key, $black);
        imagepng($img);
        imagedestroy($img);
    } elseif (function_exists("imagewbmp")) {
        header("Content-type: image/vnd.wap.wbmp");
        $img = imagecreate(69, 20);
        $black = imagecolorallocate($img, 255, 255, 255);
        $gray = imagecolorallocate($img, 102, 102, 102);
        imagefill($img, 0, 0, $gray);
        imagestring($img, 3, 14, 3, $key, $black);
        imagewbmp($img);
        imagedestroy($img);
    } else {
        $set = esetcookie("checkkey", "ebak");
        @(include "class/functions.php");
        echo ReadFiletext("images/ebak.jpg");
    }
}
Exemple #16
0
function thumbnail($inputFileName, $outputFileName, $maxSize = 100)
{
    $info = getimagesize($inputFileName);
    $type = isset($info['type']) ? $info['type'] : $info[2];
    if (!(imagetypes() & $type)) {
        return false;
    }
    $width = isset($info['width']) ? $info['width'] : $info[0];
    $height = isset($info['height']) ? $info['height'] : $info[1];
    $wRatio = $maxSize / $width;
    $hRatio = $maxSize / $height;
    $sourceImage = imagecreatefromstring(file_get_contents($inputFileName));
    if ($width <= $maxSize && $height <= $maxSize) {
        return $sourceImage;
    } elseif ($wRatio * $height < $maxSize) {
        $tHeight = ceil($wRatio * $height);
        $tWidth = $maxSize;
    } else {
        $tWidth = ceil($hRatio * $width);
        $tHeight = $maxSize;
    }
    $thumb = imagecreatetruecolor($tWidth, $tHeight);
    if ($sourceImage === false) {
        return false;
    }
    imagecopyresampled($thumb, $sourceImage, 0, 0, 0, 0, $tWidth, $tHeight, $width, $height);
    imagedestroy($sourceImage);
    $ext = strtolower(substr($outputFileName, strrpos($outputFileName, '.')));
    switch ($ext) {
        case '.gif':
            imagegif($thumb, $outputFileName);
            break;
        case '.jpg':
        case '.jpeg':
            imagejpeg($thumb, $outputFileName, 80);
            break;
        case '.png':
            imagepng($thumb, $outputFileName);
            break;
        case '.bmp':
            imagewbmp($thumb, $outputFileName);
            break;
        default:
            return false;
    }
    return true;
}
Exemple #17
0
 public function save($file, $quality = 90)
 {
     $info = pathinfo($file);
     $extension = strtolower($info['extension']);
     if (is_resource($this->image)) {
         if ($extension == 'jpeg' || $extension == 'jpg' || $extension == 'JPG') {
             imagejpeg($this->image, $file, $quality);
         } elseif ($extension == 'png') {
             imagepng($this->image, $file);
         } elseif ($extension == 'gif') {
             imagegif($this->image, $file);
         } elseif ($extension == 'bmp' || $extension == 'BMP') {
             imagewbmp($this->image, $file);
         }
         imagedestroy($this->image);
     }
 }
Exemple #18
0
function ShowKey()
{
    $key = strtolower(domake_password(4));
    $set = esetcookie('checkkey', $key);
    if (function_exists('imagejpeg')) {
        header('Content-type: image/jpeg');
        $img = imagecreate(69, 20);
        $black = imagecolorallocate($img, 255, 255, 255);
        $gray = imagecolorallocate($img, 102, 102, 102);
        imagefill($img, 0, 0, $gray);
        imagestring($img, 3, 14, 3, $key, $black);
        imagejpeg($img);
        imagedestroy($img);
    } elseif (function_exists('imagegif')) {
        header('Content-type: image/gif');
        $img = imagecreate(69, 20);
        $black = imagecolorallocate($img, 255, 255, 255);
        $gray = imagecolorallocate($img, 102, 102, 102);
        imagefill($img, 0, 0, $gray);
        imagestring($img, 3, 14, 3, $key, $black);
        imagegif($img);
        imagedestroy($img);
    } elseif (function_exists('imagepng')) {
        header('Content-type: image/png');
        $img = imagecreate(69, 20);
        $black = imagecolorallocate($img, 255, 255, 255);
        $gray = imagecolorallocate($img, 102, 102, 102);
        imagefill($img, 0, 0, $gray);
        imagestring($img, 3, 14, 3, $key, $black);
        imagepng($img);
        imagedestroy($img);
    } elseif (function_exists('imagewbmp')) {
        header('Content-type: image/vnd.wap.wbmp');
        $img = imagecreate(69, 20);
        $black = imagecolorallocate($img, 255, 255, 255);
        $gray = imagecolorallocate($img, 102, 102, 102);
        imagefill($img, 0, 0, $gray);
        imagestring($img, 3, 14, 3, $key, $black);
        imagewbmp($img);
        imagedestroy($img);
    } else {
        $set = esetcookie('checkkey', 'ebak');
        @(include 'class/functions.php');
        echo ReadFiletext('images/ebak.jpg');
    }
}
Exemple #19
0
 public function saveFile($filename)
 {
     switch ($this->type) {
         case 'jpg':
         case 'jpeg':
             imagejpeg($this->resource, $filename);
             break;
         case 'gif':
             imagegif($this->resource, $filename);
             break;
         case 'png':
             imagepng($this->resource, $filename);
             break;
         case 'bmp':
             imagewbmp($this->resource, $filename);
             break;
     }
 }
Exemple #20
0
 private function printimg()
 {
     if (function_exists("imagegif")) {
         header("Content-Type:images/gif");
         imagegif($this->img);
     } elseif (function_exists("imagejpeg")) {
         header("Content-Type:images/jpeg");
         imagejpeg($this->img);
     } elseif (function_exists("imagepng")) {
         header("Content-Type:images/png");
         imagepng($this->img);
     } elseif (function_exists("imagewbmp")) {
         header("Content-Type:images/vnd.wap.wbmp");
         imagewbmp($this->img);
     } else {
         die("No image support in this PHP server");
     }
 }
Exemple #21
0
 function display($im)
 {
     if (function_exists("imagepng")) {
         header("Content-type: image/png");
         imagepng($im);
     } elseif (function_exists("imagegif")) {
         header("Content-type: image/gif");
         imagegif($im);
     } elseif (function_exists("imagejpeg")) {
         header("Content-type: image/jpeg");
         imagejpeg($im, "", 0.5);
     } elseif (function_exists("imagewbmp")) {
         header("Content-type: image/vnd.wap.wbmp");
         imagewbmp($im);
     } else {
         return false;
     }
     return true;
 }
Exemple #22
0
 function display($im)
 {
     if (function_exists("imagepng")) {
         header("Content-type: image/png");
         imagepng($im);
     } elseif (function_exists("imagegif")) {
         header("Content-type: image/gif");
         imagegif($im);
     } elseif (function_exists("imagejpeg")) {
         header("Content-type: image/jpeg");
         imagejpeg($im, "", 0.5);
     } elseif (function_exists("imagewbmp")) {
         header("Content-type: image/vnd.wap.wbmp");
         imagewbmp($im);
     } else {
         die("Doh ! No graphical functions on this server ?");
     }
     return true;
 }
 /**
  * Write the image back to a file of specified type
  */
 protected function _outputImage($image, $type, $filename)
 {
     $output = null;
     switch ($type) {
         case IMAGETYPE_GIF:
             $output = imagegif($image, $filename);
             break;
         case IMAGETYPE_JPEG:
             $output = imagejpeg($image, $filename);
             break;
         case IMAGETYPE_PNG:
             $output = imagepng($image, $filename);
             break;
         case IMAGETYPE_WBMP:
             $output = imagewbmp($image, $filename);
             break;
     }
     return $output;
 }
Exemple #24
0
 /**
  * Saves the image to the file with the given <i>$fileName</i>, 
  * using the given image file <i>$format</i> and quality factor. <br />
  * The <i>$quality</i> factor must be in the range 0 to 100 or -1. 
  * Specify 0 to obtain small compressed files, 100 for large uncompressed files, 
  * and -1 (the default) to use the default settings.<br />
  * Returns true if the image was successfully saved; otherwise returns false.
  * 
  * @param string $fileName The path to save the file to. If not set or NULL, the raw image stream will be outputted directly.
  * @param string $format
  * @param int $quality
  * @return boolean
  */
 public function save($fileName, $format = 'png', $quality = -1)
 {
     $format = $this->type != null ? $this->type : $format;
     $return = false;
     switch ($format) {
         case 'gif':
             $return = imagegif($this->resource, $fileName);
             break;
         case 'jpg':
             $return = imagejpeg($this->resource, $fileName, $quality);
             break;
         case 'bmp':
             $return = imagewbmp($this->resource, $fileName);
             break;
         default:
             $return = imagepng($this->resource, $fileName, $quality);
             break;
     }
     return $return;
 }
function UploadPromo($fupload_name)
{
    //direktori gambar
    $vdir_upload = "joimg/promo/";
    $vfile_upload = $vdir_upload . $fupload_name;
    $tipe_file = $_FILES['fupload']['type'];
    //Simpan gambar dalam ukuran sebenarnya
    move_uploaded_file($_FILES["fupload"]["tmp_name"], $vfile_upload);
    //identitas file asli
    if ($tipe_file == "image/jpeg") {
        $im_src = imagecreatefromjpeg($vfile_upload);
    } elseif ($tipe_file == "image/png") {
        $im_src = imagecreatefrompng($vfile_upload);
    } elseif ($tipe_file == "image/gif") {
        $im_src = imagecreatefromgif($vfile_upload);
    } elseif ($tipe_file == "image/wbmp") {
        $im_src = imagecreatefromwbmp($vfile_upload);
    }
    $src_width = imageSX($im_src);
    $src_height = imageSY($im_src);
    //Simpan dalam versi small 110 pixel
    //Set ukuran gambar hasil perubahan
    $dst_width = 110;
    $dst_height = $dst_width / $src_width * $src_height;
    //proses perubahan ukuran
    $im = imagecreatetruecolor($dst_width, $dst_height);
    imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
    //Simpan gambar
    if ($_FILES["fupload"]["type"] == "image/jpeg") {
        imagejpeg($im, $vdir_upload . "s_" . $fupload_name);
    } elseif ($_FILES["fupload"]["type"] == "image/png") {
        imagepng($im, $vdir_upload . "s_" . $fupload_name);
    } elseif ($_FILES["fupload"]["type"] == "image/gif") {
        imagegif($im, $vdir_upload . "s_" . $fupload_name);
    } elseif ($_FILES["fupload"]["type"] == "image/wbmp") {
        imagewbmp($im, $vdir_upload . "s_" . $fupload_name);
    }
    //Hapus gambar di memori komputer
    imagedestroy($im_src);
    imagedestroy($im);
}
Exemple #26
0
 private function fit_image_file_to_width($file, $w)
 {
     list($width, $height) = getimagesize($file);
     $newwidth = $w;
     $newheight = $w * $height / $width;
     $mime = mime_content_type($file);
     switch ($mime) {
         case 'image/jpeg':
         case 'image/jpg':
             $src = imagecreatefromjpeg($file);
             break;
         case 'image/png':
             $src = imagecreatefrompng($file);
             break;
         case 'image/bmp':
             $src = imagecreatefromwbmp($file);
             break;
         case 'image/gif':
             $src = imagecreatefromgif($file);
             break;
     }
     $dst = imagecreatetruecolor($newwidth, $newheight);
     imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
     switch ($mime) {
         case 'image/jpeg':
             imagejpeg($dst, $file);
             break;
         case 'image/png':
             imagealphablending($dst, false);
             imagesavealpha($dst, true);
             imagepng($dst, $file);
             break;
         case 'image/bmp':
             imagewbmp($dst, $file);
             break;
         case 'image/gif':
             imagegif($dst, $file);
             break;
     }
     imagedestroy($dst);
 }
Exemple #27
0
 /**
  * Shows the resulting image (background image + text)
  * On the same format as the original background image.
  *
  * @access public
  */
 public function show()
 {
     //show thumb
     header("Content-type: image/" . $this->format);
     switch ($this->format) {
         case "JPEG":
             imagejpeg($this->img, "", $this->jpegQuality);
             break;
         case "PNG":
             imagepng($this->img, 'statscard.png');
             break;
         case "GIF":
             imagegif($this->img);
             break;
         case "WBMP":
             imagewbmp($this->img);
             break;
         default:
             imagepng($this->img);
     }
 }
Exemple #28
0
 public function getImage($ext = '', $qualidade = 100)
 {
     if (empty($ext)) {
         $ext = $this->extensao;
     }
     if (empty($ext)) {
         $ext = 'jpg';
     }
     if (strtoupper($ext) == 'JPG' || strtoupper($ext) == 'JPEG') {
         imagejpeg($this->imagem);
     } elseif (strtoupper($ext) == 'GIF') {
         @imagesavealpha($this->imagem, TRUE);
         @imagegif($this->imagem);
     } elseif (strtoupper($ext) == 'PNG') {
         imagesavealpha($this->imagem, TRUE);
         imagepng($this->imagem);
     } elseif (strtoupper($ext) == 'BMP') {
         imagewbmp($this->imagem);
     }
     @imagedestroy($this->imagem);
 }
 /**
  * Shows the resulting image (background image + text)
  * On the same format as the original background image.
  * 
  * @access public
  */
 public function show()
 {
     //show thumb
     header("Content-type: image/" . $this->format);
     //creates the text over the background image
     imagettftext($this->img, $this->fontSize, 0, $this->startPosition["x"], $this->startPosition["y"], $this->textColor, $this->fontFile, $this->text);
     switch ($this->format) {
         case "JPEG":
             imagejpeg($this->img, "", $this->jpegQuality);
             break;
         case "PNG":
             imagepng($this->img);
             break;
         case "GIF":
             imagegif($this->img);
             break;
         case "WBMP":
             imagewbmp($this->img);
             break;
         default:
             imagepng($this->img);
     }
 }
Exemple #30
0
 /**
  * 将resource以指定图片类型写入文件
  *
  * @param
  *            $type
  * @param
  *            $resource
  * @param
  *            $filename
  *            
  * @return bool
  */
 public static function write($type, $resource, $filename, $quality = 100)
 {
     switch ($type) {
         case 'gif':
         case IMAGETYPE_GIF:
             $success = imagegif($resource, $filename);
             break;
         case 'png':
         case IMAGETYPE_PNG:
             $success = imagepng($resource, $filename);
             break;
         case 'bmp':
         case IMAGETYPE_BMP:
             $success = imagewbmp($resource, $filename);
             break;
         case 'jpg':
         case 'jpeg':
         case IMAGETYPE_JPEG:
         default:
             $success = imagejpeg($resource, $filename, $quality);
             break;
     }
     @chmod($filename, 0664);
     return $success;
 }