Exemple #1
0
function courierimage($char, $width = 8, $height = 12, $pdir = 'patterns/')
{
    $im = imagecreate($width, $height);
    $background_color = imagecolorallocate($im, 255, 255, 255);
    $text_color = imagecolorallocate($im, 0, 0, 0);
    imagettftext($im, 10, 0, 0, 10, $text_color, 'cour.ttf', $char);
    $imgarray_0 = img2array($im, $width, $height);
    $imgarray_1 = img_array_split($imgarray_0);
    $imgarray_2 = img_array_split($imgarray_1);
    $ia2name = img_array_name($imgarray_2);
    if (!file_exists($pdir . $ia2name)) {
        mkdir($pdir . $ia2name);
    }
    $ia1name = img_array_name($imgarray_1);
    if (!file_exists($pdir . $ia2name . '/' . $ia1name)) {
        mkdir($pdir . $ia2name . '/' . $ia1name);
    }
    $ia0name = img_array_name($imgarray_0);
    $filename = $pdir . $ia2name . '/' . $ia1name . '/' . $ia0name . '.txt';
    if (!file_exists($filename)) {
        // $handle = fopen($filename,'w');
        writeUTF8File($filename, $char);
    }
    $filename = $pdir . $ia2name . '/' . $ia1name . '/' . $ia0name . '.gif';
    if (!file_exists($filename)) {
        ImageGif($im, $filename);
        chmod($filename, 0777);
    }
    echo '<table><tr><td>' . print_img_array($imgarray_0) . '</td><td>' . print_img_array($imgarray_1) . '</td><td>' . print_img_array($imgarray_2) . "</td><td><img src=\"{$filename}\" /></td></table>";
}
function courierimage($char, $width = 8, $height = 12, $pdir = 'patterns/')
{
    $im = imagecreate($width, $height);
    $background_color = imagecolorallocate($im, 255, 255, 255);
    $text_color = imagecolorallocate($im, 0, 0, 0);
    $imchar = $char;
    $imchar = mb_encode_numericentity($imchar, array(0x0, 0xffff, 0, 0xffff), 'UTF-8');
    // echo $imchar;
    imagettftext($im, 10, 0, 0, 10, $text_color, 'cour.ttf', $imchar);
    $imgarray_0 = img2array($im, $width, $height);
    $imgarray_1 = img_array_split($imgarray_0);
    $imgarray_2 = img_array_split($imgarray_1);
    $ia2name = img_array_name($imgarray_2);
    if (!file_exists($pdir . $ia2name)) {
        mkdir($pdir . $ia2name);
    }
    $ia1name = img_array_name($imgarray_1);
    if (!file_exists($pdir . $ia2name . '/' . $ia1name)) {
        mkdir($pdir . $ia2name . '/' . $ia1name);
    }
    $ia0name = img_array_name($imgarray_0);
    $filename = $pdir . $ia2name . '/' . $ia1name . '/' . $ia0name . '.txt';
    if (!file_exists($filename)) {
        writeUTF8File($filename, $char);
    }
    $filename = $pdir . $ia2name . '/' . $ia1name . '/' . $ia0name . '.gif';
    if (!file_exists($filename)) {
        ImageGif($im, $filename);
        chmod($filename, 0777);
    }
    // echo '<table><tr><td>'.print_img_array($imgarray_0).'</td><td>'.print_img_array($imgarray_1).'</td><td>'.print_img_array($imgarray_2)."</td><td><img src=\"$filename\" /></td></table>";
}
Exemple #3
0
function ResizeImage($Filename, $Thumbnail, $Size)
{
    $Path = pathinfo($Filename);
    $Extension = $Path['extension'];
    $ImageData = @GetImageSize($Filename);
    $Width = $ImageData[0];
    $Height = $ImageData[1];
    if ($Width >= $Height and $Width > $Size) {
        $NewWidth = $Size;
        $NewHeight = $Size / $Width * $Height;
    } elseif ($Height >= $Width and $Height > $Size) {
        $NewWidth = $Size / $Height * $Width;
        $NewHeight = $Size;
    } else {
        $NewWidth = $Width;
        $NewHeight = $Height;
    }
    $NewImage = @ImageCreateTrueColor($NewWidth, $NewHeight);
    if (preg_match('/^gif$/i', $Extension)) {
        $Image = @ImageCreateFromGif($Filename);
    } elseif (preg_match('/^png$/i', $Extension)) {
        $Image = @ImageCreateFromPng($Filename);
    } else {
        $Image = @ImageCreateFromJpeg($Filename);
    }
    if ($ImageData[2] == IMAGETYPE_GIF or $ImageData[2] == IMAGETYPE_PNG) {
        $TransIndex = imagecolortransparent($Image);
        // If we have a specific transparent color
        if ($TransIndex >= 0) {
            // Get the original image's transparent color's RGB values
            $TransColor = imagecolorsforindex($Image, $TransIndex);
            // Allocate the same color in the new image resource
            $TransIndex = imagecolorallocate($NewImage, $TransColor['red'], $TransColor['green'], $TransColor['blue']);
            // Completely fill the background of the new image with allocated color.
            imagefill($NewImage, 0, 0, $TransIndex);
            // Set the background color for new image to transparent
            imagecolortransparent($NewImage, $TransIndex);
        } elseif ($ImageData[2] == IMAGETYPE_PNG) {
            // Turn off transparency blending (temporarily)
            imagealphablending($NewImage, false);
            // Create a new transparent color for image
            $color = imagecolorallocatealpha($NewImage, 0, 0, 0, 127);
            // Completely fill the background of the new image with allocated color.
            imagefill($NewImage, 0, 0, $color);
            // Restore transparency blending
            imagesavealpha($NewImage, true);
        }
    }
    @ImageCopyResampled($NewImage, $Image, 0, 0, 0, 0, $NewWidth, $NewHeight, $Width, $Height);
    if (preg_match('/^gif$/i', $Extension)) {
        @ImageGif($NewImage, $Thumbnail);
    } elseif (preg_match('/^png$/i', $Extension)) {
        @ImagePng($NewImage, $Thumbnail);
    } else {
        @ImageJpeg($NewImage, $Thumbnail);
    }
    @chmod($Thumbnail, 0644);
}
Exemple #4
0
function gif($panels, $name)
{
    if (count($panels) > 0) {
        echo "Les images générées vont être enregistrées au format GIF.\n";
    }
    $i = 0;
    while (isset($panels[$i])) {
        ImageGif($panels[$i], $name . $i . ".gif");
        $i++;
    }
}
function Error()
{
    header('Content-Type: image/gif');
    header('Content-Disposition: inline; filename="fakeapple.gif"');
    $blank = 'R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
    // A transparent 1x1 GIF image
    $image = ImageCreateFromString(base64_decode($blank));
    ImageGif($image);
    ImageDestroy($image);
    die;
}
Exemple #6
0
 function IndexAction()
 {
     $str = "23456789ABCDEFGHJKMNPQRSTUVWXYZ";
     $code_str = str_shuffle($str);
     $code = str_split(substr($code_str, 0, 4));
     $_SESSION['VerifyCode'] = strtolower(implode('', $code));
     $width = 115;
     $height = 29;
     $im = ImageCreate($width, $height);
     // 创建图形
     ImageColorAllocate($im, 255, 255, 255);
     // 填充背景颜色为白色
     // 用淡色给图形添加杂色
     for ($i = 0; $i < 100; $i++) {
         $pxcolor = ImageColorAllocate($im, 230, 104, 66);
         ImageSetPixel($im, mt_rand(0, $width), mt_rand(0, $height), $pxcolor);
     }
     // 用深色调绘制边框
     $bordercolor = ImageColorAllocate($im, 255, 255, 255);
     ImageRectangle($im, 0, 0, $width - 1, $height - 1, $bordercolor);
     $offset = rand(10, 30);
     $font = array('View/font/UniversityRomanStd.otf');
     foreach ($code as $char) {
         $textcolor = ImageColorAllocate($im, 230, 104, 106);
         shuffle($font);
         imagettftext($im, 22, rand(-20, 40), $offset, 26, $textcolor, $font[0], $char);
         $offset += $width / 5 - rand(0, 2);
     }
     $code_str = str_shuffle($str);
     $code = str_split(substr($code_str, 0, 5));
     // 干扰字符
     $offset = rand(10, 30);
     foreach ($code as $char) {
         $textcolor = ImageColorAllocate($im, 230, 104, 66);
         shuffle($font);
         imagettftext($im, 8, rand(-20, 40), $offset, 26, $textcolor, $font[0], $char);
         $offset += rand(5, 10);
     }
     // 禁止缓存
     header("pragma:no-cache\r\n");
     header("Cache-Control:no-cache\r\n");
     header("Expires:0\r\n");
     if (ImageTypes() & IMG_PNG) {
         header('Content-Type:image/png');
         ImagePNG($im);
     } elseif (ImageTypes() & IMG_JPEG) {
         header('Content-Type:image/jpeg');
         ImageJPEG($im);
     } else {
         header('Content-Type:image/gif');
         ImageGif($im);
     }
 }
Exemple #7
0
function SetImgSize($img, $W = 0, $H = 0, $Key = 1)
{
    //echo("$img , $W ,$H , $Key");
    $rasshr = substr(strrchr($img, '.'), 1);
    //организация работы с форматами GIF JPEG PNG
    switch ($rasshr) {
        default:
        case "gif":
            $srcImage = @ImageCreateFromGIF($img);
            break;
        case "jpg":
            $srcImage = @ImageCreateFromJPEG($img);
            break;
        case "png":
            $srcImage = @ImageCreateFromPNG($img);
            break;
    }
    //определяем изначальную длинну и высоту
    $srcWidth = @ImageSX($srcImage);
    $srcHeight = @ImageSY($srcImage);
    //ресайз по заданной ширине
    if ($W != 0 && $H == 0 && $W < $srcWidth) {
        $res = ResNoDel($srcWidth, $srcHeight, $W, 0);
    }
    //ресайз по заданной высоте
    if ($W == 0 && $H != 0 && $H < $srcHeight) {
        $res = ResNoDel($srcWidth, $srcHeight, 0, $H);
    }
    //ресайз с обрезкой
    if ($W != 0 && $H != 0 && ($H < $srcHeight || $W < $srcWidth)) {
        $res = ResDel($srcWidth, $srcHeight, min($W, $srcWidth), min($H, $srcHeight), $Key);
    }
    //создаем картинку
    if ($res) {
        $endImage = @ImageCreateTrueColor($res[2], $res[3]);
        ImageCopyResampled($endImage, $srcImage, 0, 0, $res[0], $res[1], $res[2], $res[3], $res[4], $res[5]);
        unlink($img);
        switch ($rasshr) {
            case "gif":
                ImageGif($endImage, $img);
                break;
            default:
            case "jpg":
                imagejpeg($endImage, $img);
                break;
            case "png":
                imagepng($endImage, $img);
                break;
        }
        ImageDestroy($endImage);
    }
}
Exemple #8
0
function ShowImageHeader($ImageHandle)
{
    if (ImageTypes() & IMG_PNG) {
        Header("Content-type: image/png");
        ImagePng($ImageHandle);
    } elseif (ImageTypes() & IMG_GIF) {
        Header("Content-type: image/gif");
        ImageGif($ImageHandle);
    } elseif (ImageTypes() & IMG_JPEG) {
        Header("Content-type: image/jpeg");
        ImageJpeg($ImageHandle, "", 0.5);
    } else {
        die("No images support");
    }
    ImageDestroy($ImageHandle);
}
 public static function gif($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE)
 {
     $image = self::image($frame, $pixelPerPoint, $outerFrame);
     if ($filename === false) {
         Header("Content-type: image/gif");
         ImageGif($image);
     } else {
         if ($saveandprint === TRUE) {
             ImageGif($image, $filename);
             header("Content-type: image/gif");
             ImageGif($image);
         } else {
             ImageGif($image, $filename);
         }
     }
     ImageDestroy($image);
 }
Exemple #10
0
function saveImageInFormat($imageResized, $newImageName, $file_format = null)
{
    // right now this only supports gif/jpg/jpeg
    if (!$file_format) {
        $file_format = getFileExtension($newImageName);
    }
    switch ($file_format) {
        case "gif":
            header('Content-Type: image/gif');
            ImageGif($imageResized, $newImageName);
            imagedestroy($imageResized);
            // free up memory
            break;
        case "jpg":
        case "jpeg":
            header('Content-Type: image/jpeg');
            ImageJpeg($imageResized, $newImageName);
            imagedestroy($imageResized);
            break;
    }
}
Exemple #11
0
function DImage($img_src, $img_dest, $max_w = 120, $max_h = 90, $qualite = 80, $crop_from_center = 0)
{
    //ne lit pas l'image source !
    if (!function_exists('ImageCreateTrueColor')) {
        return 0;
    }
    if (!is_file($img_src)) {
        db("!is_file({$img_src})");
        return;
    }
    $startX = $startY = 0;
    #return;
    $size = @GetImageSize($img_src);
    $src_w = $size[0];
    $src_h = $size[1];
    $type = $size[2];
    $ratio = @round($src_w / $src_h, 2);
    #$_ENV['db'].="<li>".pre($size);
    if ($max_w > $src_w) {
        copy($img_src, $img_dest);
        return;
    }
    #ne pas redimensioner si plus petit
    $ratiom = round($max_w / $max_h, 2);
    if ($ratio > $ratiom) {
        $dst_w = $max_w;
        $dst_h = ceil($max_w / $ratio);
    } else {
        $dst_h = $max_h;
        $dst_w = ceil($max_h * $ratio);
    }
    #if($dst_w==0){$_GET[debug].="<li>$img_dest  $ratio> $ratiom? $dst_w $dst_h".($max_h*$rationm);return;}
    gt();
    $dst_im = ImageCreateTrueColor($dst_w, $dst_h);
    // Copie dedans l'image initiale redimensionnée
    if (!$dst_im) {
        $_ENV['db'] .= "<li>{$img_dest}  {$ratio}> {$ratiom}?  {$type}--- FAIL {$dst_w} {$dst_h}";
        return;
    }
    switch ($type) {
        case 3:
            $src_im = @ImageCreateFromPng($img_src);
            break;
        case 2:
            $src_im = @ImageCreateFromJpeg($img_src);
            break;
        case 1:
            $src_im = @ImageCreateFromGif($img_src);
            break;
    }
    if (!$src_im) {
        echo "{$img_src},{$img_dest},{$dst_w},{$dst_h},{$type},{$src_w},{$src_h}, {$type},<hr>Erreur d'upload de photo pour cause de Format JPEG Pourri !";
    }
    ReMapTree($img_dest);
    if (imagecopyresized($dst_im, $src_im, 0, 0, $startX, $startY, $dst_w, $dst_h, $src_w, $src_h)) {
        $_ENV['db'] .= " Miniature Générée";
    }
    //RESIZE TO 640 ELSE INCLUS
    switch ($type) {
        case 1:
            ImageGif($dst_im, $img_dest);
            break;
        case 2:
            ImageJpeg($dst_im, $img_dest, $qualite);
            break;
        case 3:
            ImagePng($dst_im, $img_dest, 9);
            break;
    }
    ImageDestroy($dst_im);
    ImageDestroy($src_im);
    $_ENV['db'] .= "<li>{$dst_w},{$dst_h},{$src_w},{$src_h} {$img_dest} {$ratiom}={$ratio} {$type} -";
    return;
    // Détruis les tampons
}
Exemple #12
0
 function _flipGif()
 {
     $source = ImagecreateFromGif($this->_source);
     $width = imagesx($source);
     $height = imagesy($source);
     $image = ImageCreateTrueColor($width, $height);
     if ($this->_hori) {
         for ($i = 0; $i < $width; $i++) {
             ImageCopyResampled($image, $source, $width - $i - 1, 0, $i, 0, 1, $height, 1, $height);
         }
         if ($this->_vert) {
             ImageCopyResampled($source, $image, 0, 0, 0, 0, $width, $height, $width, $height);
         }
     }
     if ($this->_vert) {
         for ($i = 0; $i < $height; $i++) {
             ImageCopyResampled($image, $source, 0, $height - $i - 1, 0, $i, $width, 1, $width, 1);
         }
     }
     ImageDestroy($source);
     $result = ImageGif($image, $this->_target);
     ImageDestroy($image);
     return $result;
 }
$phpgw_info["flags"]["noheader"] = True;
include "../header.inc.php";
Header("Content-type: image/gif");
$border = 1;
//echo $filename;
$im = openGif($filename);
/* Open the provided file */
$bg = getRGB($phpgw_info["theme"]["navbar_bg"]);
/* get navbar theme */
$fg = getRGB($phpgw_info["theme"]["navbar_text"]);
$navbar_bg = ImageColorAllocate($im, $bg["r"], $bg["g"], $bg["b"]);
$navbar_fg = ImageColorAllocate($im, $fg["r"], $fg["g"], $fg["b"]);
$dk_gray = ImageColorAllocate($im, 128, 128, 128);
$lt_gray = ImageColorAllocate($im, 192, 192, 192);
$dx = ImageSX($im);
/* get image size */
$dy = ImageSY($im);
ImageFilledRectangle($im, 0, 0, $dx, $border, $dk_gray);
/* top */
ImageFilledRectangle($im, 0, 0, $border, $dy, $dk_gray);
/* left */
ImageFilledRectangle($im, $dx - $border - 1, 0, $dx, $dy, $lt_gray);
/* right */
ImageFilledRectangle($im, 0, $dy - $border - 1, $dx, $dy, $lt_gray);
/* bottom */
//ImageGif($im,"$DOCUMENT_ROOT/kb/xml/$filename");
ImageGif($im);
ImageDestroy($im);
?>

Exemple #14
0
 /**
  * Write the icon in $im pointer to $path
  *
  * @param pointer $im Pointer to GDlib image resource
  * @param string $path Absolute path to the filename in which to write the icon.
  * @return void
  * @access private
  */
 public static function imagemake($im, $path)
 {
     if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
         @ImagePng($im, $path);
     } else {
         @ImageGif($im, $path);
     }
     if (@is_file($path)) {
         GeneralUtility::fixPermissions($path);
     }
 }
 /**
  * image::save()
  * 
  * @param mixed $path
  * @param string $newname
  * @param integer $quality
  * @return
  */
 function save($path, $newname = '', $quality = 100)
 {
     if (empty($this->error)) {
         if ($this->is_destroy) {
             $this->get_createImage();
         }
         if (is_dir($path) and is_writeable($path)) {
             if (empty($newname)) {
                 $newname = $this->create_Image_info['width'] . '_' . $this->create_Image_info['height'];
                 if (defined('PATHINFO_FILENAME')) {
                     $basename = pathinfo($this->create_Image_info['src'], PATHINFO_FILENAME);
                 } else {
                     $basename = strstr($this->create_Image_info['src'], '.') ? substr($this->create_Image_info['src'], 0, strrpos($this->create_Image_info['src'], '.')) : "";
                 }
                 if (!empty($basename)) {
                     $newname .= '_' . $basename;
                 }
             }
             $newname = preg_replace('/^\\W+|\\W+$/', '', $newname);
             $newname = preg_replace('/\\s+/', '_', $newname);
             $newname = strtolower(preg_replace('/\\W-/', '', $newname));
             $newname = preg_replace("/." . $this->create_Image_info['ext'] . "\$/", '', $newname);
             if (!preg_match("/\\/\$/", $path)) {
                 $path = $path . "/";
             }
             $newname = $path . $newname . '.' . $this->create_Image_info['ext'];
             switch ($this->create_Image_info['type']) {
                 case 'IMAGETYPE_GIF':
                     ImageGif($this->createImage, $newname);
                     break;
                 case 'IMAGETYPE_JPEG':
                     ImageJpeg($this->createImage, $newname, $quality);
                     break;
                 case 'IMAGETYPE_PNG':
                     ImagePng($this->createImage, $newname);
             }
             $this->create_Image_info['src'] = $newname;
         }
         $this->Destroy();
     }
 }
Exemple #16
0
         $im = ImageCreateFromJPEG($infile);
         break;
     case "jpeg":
         $im = ImageCreateFromJPEG($infile);
         break;
     case "png":
         $im = ImageCreateFromPNG($infile);
         break;
 }
 $im1 = imagecreatetruecolor($tn_width, $tn_height);
 $namefile = "{$newf['name']}";
 imagecopyresized($im1, $im, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
 switch ($format) {
     case "gif":
         $imagnam = "temp/{$namefile}.temp.gif";
         ImageGif($im1, $imagnam, $quality);
         echo "<img src='" . $imagnam . "' alt=''/><br/>";
         break;
     case "jpg":
         $imagnam = "temp/{$namefile}.temp.jpg";
         imageJpeg($im1, $imagnam, $quality);
         echo "<img src='" . $imagnam . "' alt=''/><br/>";
         break;
     case "jpeg":
         $imagnam = "temp/{$namefile}.temp.jpg";
         imageJpeg($im1, $imagnam, $quality);
         echo "<img src='" . $imagnam . "' alt=''/><br/>";
         break;
     case "png":
         $imagnam = "temp/{$namefile}.temp.png";
         imagePng($im1, $imagnam, $quality);
function generateImage($source_file, $cache_file, $resolution)
{
    global $sharpen, $jpg_quality;
    $extension = strtolower(pathinfo($source_file, PATHINFO_EXTENSION));
    // Check the image dimensions
    $dimensions = GetImageSize($source_file);
    $width = $dimensions[0];
    $height = $dimensions[1];
    // Do we need to downscale the image?
    if ($width <= $resolution) {
        // no, because the width of the source image is already less than the client width
        return $source_file;
    }
    // We need to resize the source image to the width of the resolution breakpoint we're working with
    $ratio = $height / $width;
    $new_width = $resolution;
    $new_height = ceil($new_width * $ratio);
    $dst = ImageCreateTrueColor($new_width, $new_height);
    // re-sized image
    switch ($extension) {
        case 'png':
            $src = @ImageCreateFromPng($source_file);
            // original image
            break;
        case 'gif':
            $src = @ImageCreateFromGif($source_file);
            // original image
            break;
        default:
            $src = @ImageCreateFromJpeg($source_file);
            // original image
            ImageInterlace($dst, true);
            // Enable interlancing (progressive JPG, smaller size file)
            break;
    }
    if ($extension == 'png') {
        imagealphablending($dst, false);
        imagesavealpha($dst, true);
        $transparent = imagecolorallocatealpha($dst, 255, 255, 255, 127);
        imagefilledrectangle($dst, 0, 0, $new_width, $new_height, $transparent);
    }
    ImageCopyResampled($dst, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    // do the resize in memory
    ImageDestroy($src);
    // sharpen the image?
    // NOTE: requires PHP compiled with the bundled version of GD (see http://php.net/manual/en/function.imageconvolution.php)
    if ($sharpen == TRUE && function_exists('imageconvolution')) {
        $intSharpness = findSharp($width, $new_width);
        $arrMatrix = array(array(-1, -2, -1), array(-2, $intSharpness + 12, -2), array(-1, -2, -1));
        imageconvolution($dst, $arrMatrix, $intSharpness, 0);
    }
    $cache_dir = dirname($cache_file);
    // does the directory exist already?
    if (!is_dir($cache_dir)) {
        if (!mkdir($cache_dir, 0755, true)) {
            // check again if it really doesn't exist to protect against race conditions
            if (!is_dir($cache_dir)) {
                // uh-oh, failed to make that directory
                ImageDestroy($dst);
                sendErrorImage("Failed to create cache directory: {$cache_dir}");
            }
        }
    }
    if (!is_writable($cache_dir)) {
        sendErrorImage("The cache directory is not writable: {$cache_dir}");
    }
    // save the new file in the appropriate path, and send a version to the browser
    switch ($extension) {
        case 'png':
            $gotSaved = ImagePng($dst, $cache_file);
            break;
        case 'gif':
            $gotSaved = ImageGif($dst, $cache_file);
            break;
        default:
            $gotSaved = ImageJpeg($dst, $cache_file, $jpg_quality);
            break;
    }
    ImageDestroy($dst);
    if (!$gotSaved && !file_exists($cache_file)) {
        sendErrorImage("Failed to create image: {$cache_file}");
    }
    return $cache_file;
}
 /**
  * Create a thumbnail image
  * @param  string  $fileName   The image filename
  */
 function createThumb($fileName, $filePath)
 {
     //copy image
     $oldFile = $this->mediaPath . $filePath . $fileName;
     $newFile = $this->mediaPath . "thumbs/" . $fileName;
     $arrSettings = $this->getSettings();
     $arrInfo = getimagesize($oldFile);
     //ermittelt die Größe des Bildes
     $setSize = $arrSettings['thumbSize']['value'];
     $strType = $arrInfo[2];
     //type des Bildes
     if ($arrInfo[0] >= $setSize || $arrInfo[1] >= $setSize) {
         if ($arrInfo[0] <= $arrInfo[1]) {
             $intFactor = $arrInfo[1] / $setSize;
             $intHeight = $setSize;
             $intWidth = $arrInfo[0] / $intFactor;
         } else {
             $intFactor = $arrInfo[0] / $setSize;
             $intResult = $arrInfo[1] / $intFactor;
             if ($intResult > $setSize) {
                 $intHeight = $setSize;
                 $intWidth = $arrInfo[0] / $intFactor;
             } else {
                 $intWidth = $setSize;
                 $intHeight = $arrInfo[1] / $intFactor;
             }
         }
     } else {
         $intWidth = $arrInfo[0];
         $intHeight = $arrInfo[1];
     }
     if (imagetypes() & IMG_GIF) {
         $boolGifEnabled = true;
     }
     if (imagetypes() & IMG_JPG) {
         $boolJpgEnabled = true;
     }
     if (imagetypes() & IMG_PNG) {
         $boolPngEnabled = true;
     }
     @touch($newFile);
     switch ($strType) {
         case 1:
             //GIF
             if ($boolGifEnabled) {
                 $handleImage1 = ImageCreateFromGif($oldFile);
                 $handleImage2 = @ImageCreateTrueColor($intWidth, $intHeight);
                 ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intWidth, $intHeight, $arrInfo[0], $arrInfo[1]);
                 ImageGif($handleImage2, $newFile);
                 ImageDestroy($handleImage1);
                 ImageDestroy($handleImage2);
             }
             break;
         case 2:
             //JPG
             if ($boolJpgEnabled) {
                 $handleImage1 = ImageCreateFromJpeg($oldFile);
                 $handleImage2 = @ImageCreateTrueColor($intWidth, $intHeight);
                 ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intWidth, $intHeight, $arrInfo[0], $arrInfo[1]);
                 ImageJpeg($handleImage2, $newFile, 95);
                 ImageDestroy($handleImage1);
                 ImageDestroy($handleImage2);
             }
             break;
         case 3:
             //PNG
             if ($boolPngEnabled) {
                 $handleImage1 = ImageCreateFromPNG($oldFile);
                 ImageAlphaBlending($handleImage1, true);
                 ImageSaveAlpha($handleImage1, true);
                 $handleImage2 = @ImageCreateTrueColor($intWidth, $intHeight);
                 ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intWidth, $intHeight, $arrInfo[0], $arrInfo[1]);
                 ImagePNG($handleImage2, $newFile);
                 ImageDestroy($handleImage1);
                 ImageDestroy($handleImage2);
             }
             break;
     }
 }
Exemple #19
0
    } else {
        if ($min % 5 == 0) {
            $len = $radius / 10;
        } else {
            $len = $radius / 25;
        }
    }
    $ang = 2 * M_PI * $min / 60;
    $x1 = sin($ang) * ($radius - $len) + $radius;
    $y1 = cos($ang) * ($radius - $len) + $radius;
    $x2 = 1 * sin($ang) * $radius;
    $y2 = 1 * cos($ang) * $radius;
    ImageLine($img, $x1, $y1, $x2, $y2, $color_black);
}
list($hour, $min, $sec) = preg_split("/-/", Date("h-i-s", time() - 3600));
$hour = $hour % 12;
$xs = intval(cos($sec * M_PI / 30 - M_PI / 2) * 0.75 * $radius + $radius);
$ys = intval(sin($sec * M_PI / 30 - M_PI / 2) * 0.75 * $radius + $radius);
$xm = intval(cos($min * M_PI / 30 - M_PI / 2) * 0.65 * $radius + $radius);
$ym = intval(sin($min * M_PI / 30 - M_PI / 2) * 0.65 * $radius + $radius);
$xh = intval(cos($hour * 5 * M_PI / 30 - M_PI / 2) * 0.5 * $radius + $radius);
$yh = intval(sin($hour * 5 * M_PI / 30 - M_PI / 2) * 0.5 * $radius + $radius);
ImageLine($img, $radius, $radius, $xs, $ys, $color_grey);
ImageLine($img, $radius, $radius - 1, $xm, $ym, $color_blue);
ImageLine($img, $radius - 1, $radius, $xm, $ym, $color_blue);
ImageLine($img, $radius, $radius - 1, $xh, $yh, $color_blue);
ImageLine($img, $radius - 1, $radius, $xh, $yh, $color_blue);
ImageArc($img, $radius, $radius, $radius / 8, $radius / 8, 0, 360, $color_red);
ImageFillToBorder($img, $radius, $radius, $color_red, $color_red);
ImageGif($img);
ImageDestroy($img);
Exemple #20
0
function init_wanted($id_troll)
{
    $lesTrolls = selectDbTrolls($id_troll);
    $res = $lesTrolls[1];
    $lesVengeances = selectDbVengeances($id_troll);
    $nb_vengeances = count($lesVengeances);
    $lesGriefs = selectDbGriefs($id_troll);
    $nb_griefs = count($lesGriefs);
    $impact = PATH_IMG . "wanted_impact_{$nb_vengeances}.png";
    if ($res[nom_image_troll] != "") {
        $fp = @fopen($res["nom_image_troll"], "r");
    } else {
        $fp = false;
    }
    /*	print_r($res);
    	die("test $res[nom_image_troll]");*/
    $images = array(ImageCreateFromPng(PATH_IMG . "wanted_fond.png"), ImageCreateFromPng(PATH_IMG . "wanted_fond.png"), ImageCreateFromPng(PATH_IMG . "wanted_transparent.png"), ImageCreateFromPng($impact), ImageCreateFromPng(PATH_IMG . "wanted_grief_{$nb_griefs}.png"));
    if ($fp == false) {
        $images[2] = ImageCreateFromPng(PATH_IMG . "wanted_interrogation.png");
    } elseif (preg_match("/.*(png|Png|PNG)/", $res["nom_image_troll"])) {
        $img = ImageCreateFromJpeg($res["nom_image_troll"]);
    } elseif (preg_match("/.*(jpg|jpeg|JPG|JPEG)/", $res["nom_image_troll"])) {
        $img = ImageCreateFromJpeg($res["nom_image_troll"]);
    } elseif (preg_match("/.*(gif|Gif|GIF)/", $res["nom_image_troll"])) {
        $img = ImageCreateFromGif($res["nom_image_troll"]);
    } elseif (preg_match("/.*mountyhall.*Blason_PJ*./", $res["nom_image_troll"])) {
        $img = @ImageCreateFromGif($res["nom_image_troll"]);
        if (!$img) {
            $img = @ImageCreateFromJpeg($res["nom_image_troll"]);
            if (!$img) {
                $img = @ImageCreateFromPng($res["nom_image_troll"]);
                if (!$img) {
                    $fp = false;
                }
            }
        }
    } else {
        $images[2] = ImageCreateFromPng(PATH_IMG . "wanted_interrogation.png");
        fclose($fp);
        $fp = false;
    }
    if ($fp != false) {
        $img_src_w = imagesx($img);
        $img_src_h = imagesy($img);
        $img_dest_w = 43;
        //150 75 33
        $img_dest_h = 55;
        // 231 115 55
        imagecopyresized($images[2], $img, 30, 44, 0, 0, $img_dest_w, $img_dest_h, $img_src_w, $img_src_h);
        fclose($fp);
    }
    $image = imagemergealpha($images);
    /* -------- Destruction ------- */
    foreach ($images as $img) {
        ImageDestroy($img);
    }
    putenv('GDFONTPATH=' . realpath('.'));
    $font = "Wanted";
    $font_size = 5;
    $noir = ImageColorAllocate($image, 0, 0, 0);
    //imagettftext($image, $font_size, 0, 10, 38, $noir, $font, $res['nom_troll']);
    imagestring($image, 2, 10, 30, $res['nom_troll'], $noir);
    //imagettftext($image, $font_size, 0, 10, 38, $noir, $font, $res['nom_troll']);
    /* -------- Génération ------- */
    /* ImagePng($image,PATH_IMG.'cache/'.$res[nom_image_troll]."_avatar.png"); */
    /* -------- Cache -------- */
    $fondclair = ImageCreateFromPng(PATH_IMG . 'wanted_fond.png');
    $gifclair = imagemergealpha(array($fondclair, $image));
    $back_color = imagecolorallocate($gifclair, 0xa9, 0xb1, 0xd3);
    ImageTrueColorToPalette($gifclair, false, 256);
    ImageGif($gifclair, PATH_IMG . "cache/wanted_{$id_troll}.gif");
    /* -------- Affichage -------- */
    //Header('Content-Type: image/gif');
    // BUG PHP5
    //ImageGif($gifclair);
    $string = file_get_contents(PATH_IMG . "cache/wanted_{$id_troll}.gif");
    echo $string;
    ImageDestroy($fondclair);
    ImageDestroy($gifclair);
}
Exemple #21
0
 function PushImage()
 {
     switch ($this->file_format) {
         case "png":
             ImagePng($this->img);
             break;
         case "jpg":
             ImageJPEG($this->img);
             break;
         case "gif":
             ImageGif($this->img);
             break;
     }
     ImageDestroy($this->img);
 }
function resizeMyImage($file, $destination, $w, $h)
{
    //Get the original image dimensions + type
    list($source_width, $source_height, $source_type) = getimagesize($file);
    //Figure out if we need to create a new JPG, PNG or GIF
    $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
    if ($ext == "jpg" || $ext == "jpeg") {
        $source_gdim = imagecreatefromjpeg($file);
    } elseif ($ext == "png") {
        $source_gdim = imagecreatefrompng($file);
    } elseif ($ext == "gif") {
        $source_gdim = imagecreatefromgif($file);
    } else {
        //Invalid file type? Return.
        return;
    }
    //If a width is supplied, but height is false, then we need to resize by width instead of cropping
    if ($w && !$h) {
        $ratio = $w / $source_width;
        $temp_width = $w;
        $temp_height = $source_height * $ratio;
        $desired_gdim = imagecreatetruecolor($temp_width, $temp_height);
        imagecopyresampled($desired_gdim, $source_gdim, 0, 0, 0, 0, $temp_width, $temp_height, $source_width, $source_height);
    } else {
        $source_aspect_ratio = $source_width / $source_height;
        $desired_aspect_ratio = $w / $h;
        if ($source_aspect_ratio > $desired_aspect_ratio) {
            /*
             * Triggered when source image is wider
             */
            $temp_height = $h;
            $temp_width = (int) ($h * $source_aspect_ratio);
        } else {
            /*
             * Triggered otherwise (i.e. source image is similar or taller)
             */
            $temp_width = $w;
            $temp_height = (int) ($w / $source_aspect_ratio);
        }
        /*
         * Resize the image into a temporary GD image
         */
        $temp_gdim = imagecreatetruecolor($temp_width, $temp_height);
        imagecopyresampled($temp_gdim, $source_gdim, 0, 0, 0, 0, $temp_width, $temp_height, $source_width, $source_height);
        /*
         * Copy cropped region from temporary image into the desired GD image
         */
        $x0 = ($temp_width - $w) / 2;
        $y0 = ($temp_height - $h) / 2;
        $desired_gdim = imagecreatetruecolor($w, $h);
        imagecopy($desired_gdim, $temp_gdim, 0, 0, $x0, $y0, $w, $h);
    }
    /*
     * Render the image
     * Alternatively, you can save the image in file-system or database
     */
    if ($ext == "jpg" || $ext == "jpeg") {
        ImageJpeg($desired_gdim, $destination, 100);
    } elseif ($ext == "png") {
        ImagePng($desired_gdim, $destination);
    } elseif ($ext == "gif") {
        ImageGif($desired_gdim, $destination);
    } else {
        return;
    }
    ImageDestroy($desired_gdim);
}
function chop_png($path, $pdir = 'patterns/', $chopx = 8, $chopy = 12, $threshold = 0.25)
{
    $tdir = 'temp/';
    $size = getimagesize($path);
    $im = imagecreatefrompng($path);
    $width = $size[0];
    $height = $size[1];
    $output = '';
    for ($y = 0; $y < intval($height / $chopy); $y++) {
        for ($x = 0; $x < intval($width / $chopx); $x++) {
            $dest = imagecreate($chopx, $chopy);
            imagecopy($dest, $im, 0, 0, $x * $chopx, $y * $chopy, $chopx, $chopy);
            $filename = $tdir . $x . '_' . $y . '.gif';
            //gif name
            ImageGif($dest, $filename);
            //write gif
            $da0 = img2array($dest, $chopx, $chopy);
            //1:1
            imagedestroy($dest);
            $da1 = img_array_split($da0, $threshold);
            //1:2
            $da2 = img_array_split($da1, $threshold);
            //1:4
            $da2n = img_array_name($da2);
            //1:4 name
            // $da0n = img_array_name($da0);//1:1 name
            // echo '<img src="'.$filename.'"> -> '.$da0n."\n";
            $dir3 = $pdir;
            if (file_exists($dir3 . $da2n)) {
                // echo $da2n.'<br />';
                $da1n = img_array_name($da1);
                $dir2 = $dir3 . $da2n . '/';
                if (file_exists($dir2 . $da1n)) {
                    $da0n = img_array_name($da0);
                    // echo $da0n.'<br />';
                    $dir1 = $dir2 . $da1n . '/';
                    if (file_exists($dir1 . $da0n . '.txt')) {
                        // echo $da0n.'<br />';
                        $output .= file_get_contents($dir1 . $da0n . '.txt');
                    } else {
                        $scan = scandir($dir1);
                        // echo $scan[3].'<br />';
                        $output .= file_get_contents($dir1 . $scan[3]);
                    }
                } else {
                    $scan = scandir($dir2);
                    array_shift($scan);
                    array_shift($scan);
                    $dirs2vals = array();
                    foreach ($scan as $dname) {
                        $dirs2vals[nameSum($dname)] = $dname;
                    }
                    //print_r($dirs2vals);
                    $weight = nameSum($da1n);
                    if (isset($dirs2vals[$weight])) {
                        $thisdir = $dirs2vals[$weight];
                    } else {
                        $thisdir = array_pop($dirs2vals);
                    }
                    // echo $thisdir.'<br />';
                    $dirs0files = scandir($dir2 . $thisdir);
                    $output .= file_get_contents($dir2 . $thisdir . '/' . $dirs0files[3]);
                }
            } else {
                // echo $da2n.'<br />';
                $scan = scandir($dir3);
                array_shift($scan);
                //get rid of self
                array_shift($scan);
                //get rid of parent
                //store children as weights
                $dirs3vals = array();
                foreach ($scan as $dname) {
                    $dirs3vals[nameSum($dname)] = $dname;
                }
                $weight = nameSum($da2n);
                //get weight of image piece
                asort($dirs3vals);
                if (isset($dirs3vals[$weight])) {
                    $thisdir = $dirs3vals[$weight];
                } else {
                    // echo 'last ';
                    $thisdir = array_pop($dirs3vals);
                    //select the last(darkest)
                }
                // echo $da2n.' -> '.$thisdir.'<br />';
                $tdir2 = $dir3 . $thisdir . '/';
                $subdir = scandir($tdir2);
                array_shift($subdir);
                array_shift($subdir);
                // asort($subdir);
                $subdir = array_pop($subdir) . '/';
                // echo $da2n.' -> '.$subdir.'<br />';
                $subdirFiles = scandir($tdir2 . $subdir);
                $val = file_get_contents($tdir2 . $subdir . $subdirFiles[3]);
                //0 self 1 parent 2 gif 3 txt
                // echo $da2n.' -> '.$val . '<br />';
                $output .= $val;
            }
        }
        //end forx
        $output .= "\n";
    }
    //end fory
    return $output;
}
Exemple #24
0
/* *************************
error_reporting(4);
$im_test = ImageCreate(2,2);
$test = (ImagePng($im_test)) ;
ImageDestroy($im_test);
exit;
**************************** */
?>

<TABLE border=1>
<TR><TD>Test to see if GIF graphs work</TD></TR>
<TR><TD>
<?php 
$im_test = ImageCreate(1, 1);
echo "<!--";
if (!ImageGif($im_test)) {
    echo "-->";
    echo "GIF NOT ENABLED<br>";
} else {
    echo "-->";
    ?>
	<IMG SRC="inline_image.php?file_format=gif&which_title=YES_GIF_IS_ENABLED"></TD></TR>
	<?php 
}
ImageDestroy($im_test);
?>
</TABLE>
<p>
<TABLE border=1>
<TR><TD>Test to see if PNG graphs work</TD></TR>
<TR><TD>
Exemple #25
0
 function PushImage()
 {
     switch ($this->file_format) {
         case 'png':
             ImagePng($this->img);
             break;
         case 'jpg':
             ImageJPEG($this->img);
             break;
         case 'gif':
             ImageGif($this->img);
             break;
     }
     ImageDestroy($this->img);
 }
Exemple #26
0
 function show($name = "")
 {
     if ($this->error) {
         $this->show_error_image();
         return;
     }
     $size = GetImageSize($this->file);
     $new_size = $this->calc_image_size($size[0], $size[1]);
     #
     # Good idea from Mariano Cano P�rez
     # Requires GD 2.0.1 (PHP >= 4.0.6)
     #
     if (function_exists("ImageCreateTrueColor")) {
         $new_image = ImageCreateTrueColor($new_size[0], $new_size[1]);
     } else {
         $new_image = ImageCreate($new_size[0], $new_size[1]);
     }
     switch ($this->format) {
         case "GIF":
             $old_image = ImageCreateFromGif($this->file);
             break;
         case "JPEG":
             $old_image = ImageCreateFromJpeg($this->file);
             break;
         case "PNG":
             $old_image = ImageCreateFromPng($this->file);
             break;
     }
     #
     # Good idea from Michael Wald
     # Requires GD 2.0.1 (PHP >= 4.0.6)
     #
     if (function_exists("ImageCopyResampled")) {
         ImageCopyResampled($new_image, $old_image, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);
     } else {
         ImageCopyResized($new_image, $old_image, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);
     }
     switch ($this->format) {
         case "GIF":
             if (!empty($name)) {
                 ImageGif($new_image, $name);
             } else {
                 header("Content-type: image/gif");
                 ImageGif($new_image);
             }
             break;
         case "JPEG":
             if (!empty($name)) {
                 ImageJpeg($new_image, $name, $this->jpeg_quality);
             } else {
                 header("Content-type: image/jpeg");
                 ImageJpeg($new_image, "", $this->jpeg_quality);
             }
             break;
         case "PNG":
             if (!empty($name)) {
                 ImagePng($new_image, $name);
             } else {
                 header("Content-type: image/png");
                 ImagePng($new_image);
             }
             break;
     }
     ImageDestroy($new_image);
     ImageDestroy($old_image);
     return;
 }
Exemple #27
0
<?php

if (!isset($label)) {
    $label = "Hello";
}
#	$gif = ImageCreate(125,30);
$gif = ImageCreateFromGif("/home/www/pals/html/campbell/src/iowa.gif");
#	$bg = ImageColorTransparent($gif,1);
$white = ImageColorAllocate($gif, 250, 250, 250);
$black = ImageColorAllocate($gif, 0, 0, 0);
$green = ImageColorAllocate($gif, 0, 255, 0);
ImageFilledRectangle($gif, 0, 0, 125, 30, $green);
ImageFilledRectangle($gif, 2, 2, 123, 28, $white);
#	ImageArc($gif, 100, 100, 100, 50, 145, 90, $black);
ImageTTFText($gif, 20, 0, 10, 20, $black, "/usr/X11R6/lib/X11/fonts/winttf/handgotn.TTF", "Weather");
#	ImageString($gif, 5, 70, 5,$label,$black);
#	ImageString($gif, 5, 71, 6,$label,$white);
#	header("content-type: image/gif");
ImageGif($gif);
Exemple #28
0
function dzthumb($srcfile,$dstfile,$dstw,$dsth=0,$mode=0,$data=''){
	//mode=0为固定宽高,画质裁切不变形
	//mode=1为固定宽高,画质会拉伸变形
	//mode=2为可变宽高,宽高不超过指定大小
	//mode=3为固定宽度,高度随比例变化
	$data=$data==''?@GetImageSize($srcfile):$data;
	if(!$data) return false;
	if($data[2]==2) $im=@ImageCreateFromJPEG($srcfile);
	elseif ($data[2]==1) $im=@ImageCreateFromGIF($srcfile);
	elseif($data[2]==3) $im=@ImageCreateFromPNG($srcfile);
	list($img_w, $img_h) = $data;
	if($dsth==0) $mode=3;
	if($mode==0){
		$imgratio = $img_w / $img_h;
		$thumbratio = $dstw / $dsth;
		if($imgratio >= 1 && $imgratio >= $thumbratio || $imgratio < 1 && $imgratio > $thumbratio) {
			$cuty = $img_h;
			$cutx = $cuty * $thumbratio;
		} elseif($imgratio >= 1 && $imgratio <= $thumbratio || $imgratio < 1 && $imgratio < $thumbratio) {
			$cutx = $img_w;
			$cuty = $cutx / $thumbratio;
		}
		$cx = $cutx;
		$cy = $cuty;
	}elseif($mode==1){
		$cx = $img_w;
		$cy = $img_h;
	}elseif ($mode==2){
		$cx = $img_w;
		$cy = $img_h;
		$bit=$img_w/$img_h;
		if($dstw/$dsth>$bit){
			$dstw=($img_w/$img_h)*$dsth;
		}else{
			$dsth=($img_h/$img_w)*$dstw;
		}
	}
	elseif($mode==3){
		$cx = $img_w;
		$cy = $img_h;
		$dsth=$dstw * $img_h / $img_w;
	}
	$ni=imagecreatetruecolor($dstw,$dsth);
	ImageCopyResampled($ni,$im,0,0,0,0,$dstw,$dsth, $cx, $cy);
	clearstatcache();
	if($data[2]==2) ImageJPEG($ni,$dstfile,60);
	elseif($data[2]==1) ImageGif($ni,$dstfile);
	elseif($data[2]==3) ImagePNG($ni,$dstfile);
	return true;
}
Exemple #29
0
 /**
  * Outputs the image to the screen, or saves to $name if supplied.  Quality of JPEG images can be controlled with the $quality variable
  *
  * @param int $quality
  * @param string $name
  */
 function show($quality = 100, $name = '')
 {
     switch ($this->format) {
         case 'GIF':
             if ($name != '') {
                 @ImageGif($this->newImage, $name) or $this->error = true;
             } else {
                 header('Content-type: image/gif');
                 ImageGif($this->newImage);
             }
             break;
         case 'JPG':
             if ($name != '') {
                 @ImageJpeg($this->newImage, $name, $quality) or $this->error = true;
             } else {
                 header('Content-type: image/jpeg');
                 ImageJpeg($this->newImage, NULL, $quality);
             }
             break;
         case 'PNG':
             if ($name != '') {
                 @ImagePng($this->newImage, $name) or $this->error = true;
             } else {
                 header('Content-type: image/png');
                 ImagePng($this->newImage);
             }
             break;
     }
 }
Exemple #30
0
 function display()
 {
     $this->draw_legends(2);
     #$this->draw_margins();
     ImageGif($this->im, "/tmp/pie.gif");
     Header("Content-type: image/gif");
     ImageGif($this->im);
 }