function PrintImage()
 {
     // Browser cache stuff submitted by Thiemo Nagel
     if (!$this->browser_cache && !$this->is_inline) {
         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
         header('Cache-Control: no-cache, must-revalidate');
         header('Pragma: no-cache');
     }
     switch ($this->file_format) {
         case 'png':
             if (!$this->is_inline) {
                 Header('Content-type: image/png');
             }
             if ($this->is_inline && $this->output_file != '') {
                 ImagePng($this->img, $this->output_file);
             } else {
                 ImagePng($this->img);
             }
             break;
         case 'jpg':
             if (!$this->is_inline) {
                 Header('Content-type: image/jpeg');
             }
             if ($this->is_inline && $this->output_file != '') {
                 ImageJPEG($this->img, $this->output_file);
             } else {
                 ImageJPEG($this->img);
             }
             break;
         case 'gif':
             if (!$this->is_inline) {
                 Header('Content-type: image/gif');
             }
             if ($this->is_inline && $this->output_file != '') {
                 ImageGIF($this->img, $this->output_file);
             } else {
                 ImageGIF($this->img);
             }
             break;
         case 'wbmp':
             // wireless bitmap, 2 bit.
             if (!$this->is_inline) {
                 Header('Content-type: image/wbmp');
             }
             if ($this->is_inline && $this->output_file != '') {
                 ImageWBMP($this->img, $this->output_file);
             } else {
                 ImageWBMP($this->img);
             }
             break;
         default:
             $this->PrintError('PrintImage(): Please select an image type!');
             break;
     }
     return TRUE;
 }
 function PrintImage()
 {
     if ($this->browser_cache == 0 && $this->is_inline == 0) {
         //Submitted by Thiemo Nagel
         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
         header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . 'GMT');
         header('Cache-Control: no-cache, must-revalidate');
         header('Pragma: no-cache');
     }
     switch ($this->file_format) {
         case "png":
             if ($this->is_inline == 0) {
                 Header('Content-type: image/png');
             }
             if ($this->is_inline == 1 && $this->output_file != "") {
                 ImagePng($this->img, $this->output_file);
             } else {
                 ImagePng($this->img);
             }
             break;
         case "jpg":
             if ($this->is_inline == 0) {
                 Header('Content-type: image/jpeg');
             }
             if ($this->is_inline == 1 && $this->output_file != "") {
                 ImageJPEG($this->img, $this->output_file);
             } else {
                 ImageJPEG($this->img);
             }
             break;
         case "gif":
             if ($this->is_inline == 0) {
                 Header('Content-type: image/gif');
             }
             if ($this->is_inline == 1 && $this->output_file != "") {
                 ImageGIF($this->img, $this->output_file);
             } else {
                 ImageGIF($this->img);
             }
             break;
         case "wbmp":
             if ($this->is_inline == 0) {
                 Header('Content-type: image/wbmp');
             }
             if ($this->is_inline == 1 && $this->output_file != "") {
                 ImageWBMP($this->img, $this->output_file);
             } else {
                 ImageWBMP($this->img);
             }
             break;
         default:
             $this->PrintError('Please select an image type!<br />');
             break;
     }
     ImageDestroy($this->img);
     return true;
 }
Exemple #3
0
/**
 * make thumbnail image and save
 */
function thumbnail($file, $save_filename, $max_width = 100, $max_height = 100, $sizeChg = 1)
{
    $img_info = @getimagesize($file);
    //이미지 사이즈를 확인합니다.
    //이미지 타입을 이용해 변수를 재지정해줍니다.
    //------------------------------------------------------
    // Imagetype Constants
    //------------------------------------------------------
    // 1 IMAGETYPE_GIF
    // 2 IMAGETYPE_JPEG
    // 3 IMAGETYPE_PNG
    // 4 IMAGETYPE_SWF
    // 5 IMAGETYPE_PSD
    // 6 IMAGETYPE_BMP
    // 7 IMAGETYPE_TIFF_II (intel byte order)
    // 8 IMAGETYPE_TIFF_MM (motorola byte order)
    // 9 IMAGETYPE_JPC
    // 10 IMAGETYPE_JP2
    // 11 IMAGETYPE_JPX
    // 12 IMAGETYPE_JB2
    // 13 IMAGETYPE_SWC
    // 14 IMAGETYPE_IFF
    // 15 IMAGETYPE_WBMP
    // 16 IMAGETYPE_XBM
    //------------------------------------------------------
    if ($img_info[2] == 1) {
        $src_img = ImageCreateFromGIF($file);
    } elseif ($img_info[2] == 2) {
        $src_img = ImageCreateFromJPEG($file);
    } elseif ($img_info[2] == 3) {
        $src_img = ImageCreateFromPNG($file);
    } elseif ($img_info[2] == 4) {
        $src_img = ImageCreateFromWBMP($file);
    } else {
        return false;
    }
    $img_info = getImageSize($file);
    //원본이미지의 정보를 얻어옵니다
    $img_width = $img_info[0];
    $img_height = $img_info[1];
    $crt_width = $max_width;
    //생성되면 이미지 사이즈
    $crt_height = $max_height;
    //1.가로 세로 원본비율을 맞추고, 남은 영역에 색채워서 정해진 크기로 생성
    if ($sizeChg == 1) {
        if ($img_width / $max_width == $img_height / $max_height) {
            //원본과 썸네일의 가로세로비율이 같은경우
            $dst_x = 0;
            $dst_y = 0;
            $dst_width = $max_width;
            $dst_height = $max_height;
        } elseif ($img_width / $max_width < $img_height / $max_height) {
            //세로에 기준을 둔경우
            $dst_x = ($max_width - $img_width * ($max_height / $img_height)) / 2;
            $dst_y = 0;
            $dst_width = $max_height * ($img_width / $img_height);
            $dst_height = $max_height;
        } else {
            //가로에 기준을 둔경우
            $dst_x = 0;
            $dst_y = ($max_height - $img_height * ($max_width / $img_width)) / 2;
            $dst_width = $max_width;
            $dst_height = $max_width * ($img_height / $img_width);
        }
        //2.가로 세로 원본비율을 맞추고, 남은 영역없이 이미지만 컷 생성
    } else {
        if ($sizeChg == 2) {
            if ($img_width / $max_width == $img_height / $max_height) {
                //원본과 썸네일의 가로세로비율이 같은경우
                $dst_width = $max_width;
                $dst_height = $max_height;
            } elseif ($img_width / $max_width < $img_height / $max_height) {
                //세로에 기준을 둔경우
                $dst_width = $max_height * ($img_width / $img_height);
                $dst_height = $max_height;
            } else {
                //가로에 기준을 둔경우
                $dst_width = $max_width;
                $dst_height = $max_width * ($img_height / $img_width);
            }
            $dst_x = 0;
            $dst_y = 0;
            $crt_width = $dst_width;
            $crt_height = $dst_height;
            //3.가로 세로 원본비율을 맞추지 않고, 정해진 크기대로 생성
        } else {
            $dst_width = $max_width;
            $dst_height = $max_height;
            $dst_x = 0;
            $dst_y = 0;
        }
    }
    $dst_img = imagecreatetruecolor($crt_width, $crt_height);
    //타겟이미지를 생성합니다
    $white = imagecolorallocate($dst_img, 255, 255, 255);
    imagefill($dst_img, 0, 0, $white);
    ImageCopyResized($dst_img, $src_img, $dst_x, $dst_y, 0, 0, $dst_width, $dst_height, $img_width, $img_height);
    //타겟이미지에 원하는 사이즈의 이미지를 저장합니다
    ImageInterlace($dst_img);
    switch ($img_info[2]) {
        case "1":
            ImageGIF($dst_img, $save_filename);
            break;
        case "2":
            ImageJPEG($dst_img, $save_filename);
            break;
        case "3":
            imagealphablending($dst_img, false);
            imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, 0, 0, $dst_width, $dst_height, $img_width, $img_height);
            //(생성이미지,원소스이미지,시작점X,시작점Y,원본소스상 시작점X,원본소스상 시작점Y,생성이미지너비, 생성이미지높이,원이미지너비,원이미지높이)
            imagesavealpha($dst_img, true);
            ImagePNG($dst_img, $save_filename, 0);
            break;
        case "4":
            ImageWBMP($dst_img, $save_filename);
            break;
    }
    ImageDestroy($dst_img);
    ImageDestroy($src_img);
}
 function ErrorImage($text, $width = 400, $height = 100)
 {
     $this->error = $text;
     if (!$this->config_error_die_on_error) {
         return true;
     }
     if (!empty($this->err) || !empty($this->config_error_message_image_default)) {
         // Show generic custom error image instead of error message
         // for use on production sites where you don't want debug messages
         if (@$this->err == 'showerror') {
             // fall through and actually show error message even if default error image is set
         } else {
             header('Location: ' . (!empty($this->err) ? $this->err : $this->config_error_message_image_default));
             exit;
         }
     }
     if (@$this->f == 'text') {
         // bypass all GD functions and output text error message
         die('<PRE>' . $text . '</PRE>');
     }
     $FontWidth = ImageFontWidth($this->config_error_fontsize);
     $FontHeight = ImageFontHeight($this->config_error_fontsize);
     $LinesOfText = explode("\n", wordwrap($text, floor($width / $FontWidth), "\n", true));
     $height = max($height, count($LinesOfText) * $FontHeight);
     if (headers_sent()) {
         echo "\n" . '**Headers already sent, dumping error message as text:**<br>' . "\n\n" . $text;
     } elseif ($gdimg_error = @ImageCreate($width, $height)) {
         $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_error, $this->config_error_bgcolor, true);
         $text_color = phpthumb_functions::ImageHexColorAllocate($gdimg_error, $this->config_error_textcolor, true);
         ImageFilledRectangle($gdimg_error, 0, 0, $width, $height, $background_color);
         $lineYoffset = 0;
         foreach ($LinesOfText as $line) {
             ImageString($gdimg_error, $this->config_error_fontsize, 2, $lineYoffset, $line, $text_color);
             $lineYoffset += $FontHeight;
         }
         if (function_exists('ImageTypes')) {
             $imagetypes = ImageTypes();
             if ($imagetypes & IMG_PNG) {
                 header('Content-type: image/png');
                 ImagePNG($gdimg_error);
             } elseif ($imagetypes & IMG_GIF) {
                 header('Content-type: image/gif');
                 ImageGIF($gdimg_error);
             } elseif ($imagetypes & IMG_JPG) {
                 header('Content-type: image/jpeg');
                 ImageJPEG($gdimg_error);
             } elseif ($imagetypes & IMG_WBMP) {
                 header('Content-type: image/wbmp');
                 ImageWBMP($gdimg_error);
             }
         }
         ImageDestroy($gdimg_error);
     }
     if (!headers_sent()) {
         echo "\n" . '**Failed to send graphical error image, dumping error message as text:**<br>' . "\n\n" . $text;
     }
     exit;
     return true;
 }
 function ErrorImage($text, $width = 0, $height = 0, $forcedisplay = false)
 {
     $width = $width ? $width : $this->config_error_image_width;
     $height = $height ? $height : $this->config_error_image_height;
     $text = 'phpThumb() v' . $this->phpthumb_version . "\n" . 'http://phpthumb.sourceforge.net' . "\n\n" . ($this->config_disable_debug ? 'Error messages disabled' : $text);
     $this->FatalError($text);
     $this->DebugMessage($text, __FILE__, __LINE__);
     $this->purgeTempFiles();
     if ($this->phpThumbDebug && !$forcedisplay) {
         return false;
     }
     if (!$this->config_error_die_on_error && !$forcedisplay) {
         return false;
     }
     if ($this->config_error_silent_die_on_error) {
         exit;
     }
     if ($this->err || $this->config_error_message_image_default) {
         // Show generic custom error image instead of error message
         // for use on production sites where you don't want debug messages
         if ($this->err == 'showerror' || $this->phpThumbDebug) {
             // fall through and actually show error message even if default error image is set
         } else {
             header('Location: ' . ($this->err ? $this->err : $this->config_error_message_image_default));
             exit;
         }
     }
     $this->setOutputFormat();
     if (!$this->thumbnailFormat || phpthumb_functions::gd_version() < 1) {
         $this->thumbnailFormat = 'text';
     }
     if (@$this->thumbnailFormat == 'text') {
         // bypass all GD functions and output text error message
         if (!headers_sent()) {
             header('Content-type: text/plain');
             echo $text;
         } else {
             echo '<pre>' . htmlspecialchars($text) . '</pre>';
         }
         exit;
     }
     $FontWidth = ImageFontWidth($this->config_error_fontsize);
     $FontHeight = ImageFontHeight($this->config_error_fontsize);
     $LinesOfText = explode("\n", @wordwrap($text, floor($width / $FontWidth), "\n", true));
     $height = max($height, count($LinesOfText) * $FontHeight);
     $headers_file = '';
     $headers_line = '';
     if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.0', '>=') && headers_sent($headers_file, $headers_line)) {
         echo "\n" . '**Headers already sent in file "' . $headers_file . '" on line "' . $headers_line . '", dumping error message as text:**<br><pre>' . "\n\n" . $text . "\n" . '</pre>';
     } elseif (headers_sent()) {
         echo "\n" . '**Headers already sent, dumping error message as text:**<br><pre>' . "\n\n" . $text . "\n" . '</pre>';
     } elseif ($gdimg_error = ImageCreate($width, $height)) {
         $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_error, $this->config_error_bgcolor, true);
         $text_color = phpthumb_functions::ImageHexColorAllocate($gdimg_error, $this->config_error_textcolor, true);
         ImageFilledRectangle($gdimg_error, 0, 0, $width, $height, $background_color);
         $lineYoffset = 0;
         foreach ($LinesOfText as $line) {
             ImageString($gdimg_error, $this->config_error_fontsize, 2, $lineYoffset, $line, $text_color);
             $lineYoffset += $FontHeight;
         }
         if (function_exists('ImageTypes')) {
             $imagetypes = ImageTypes();
             if ($imagetypes & IMG_PNG) {
                 header('Content-Type: image/png');
                 ImagePNG($gdimg_error);
             } elseif ($imagetypes & IMG_GIF) {
                 header('Content-Type: image/gif');
                 ImageGIF($gdimg_error);
             } elseif ($imagetypes & IMG_JPG) {
                 header('Content-Type: image/jpeg');
                 ImageJPEG($gdimg_error);
             } elseif ($imagetypes & IMG_WBMP) {
                 header('Content-Type: image/vnd.wap.wbmp');
                 ImageWBMP($gdimg_error);
             }
         }
         ImageDestroy($gdimg_error);
     }
     if (!headers_sent()) {
         echo "\n" . '**Failed to send graphical error image, dumping error message as text:**<br>' . "\n\n" . $text;
     }
     exit;
     return true;
 }
 static function crop($_filename, $width, $height)
 {
     $filename = self::pullFilename($_filename);
     if (empty($filename)) {
         return null;
     }
     $absPath = $_SERVER["DOCUMENT_ROOT"] . '/';
     $absPathSource = $absPath;
     $absPathSourceFileName = substr($filename, 1, 1) == '/' ? $absPathSource . $filename : $absPathSource . '/' . $filename;
     $md5Filename = md5($filename) . "-c-{$width}-{$height}";
     $imgExt = pathinfo($filename, PATHINFO_EXTENSION);
     if (file_exists($absPath . self::$pathToCropImg . $md5Filename . '.' . $imgExt)) {
         return '/' . self::$pathToCropImg . $md5Filename . '.' . $imgExt;
     }
     if (!file_exists($absPathSourceFileName)) {
         return null;
     }
     list($width_orig, $height_orig) = getimagesize($absPathSourceFileName);
     $width_orig_ = $width_orig;
     $height_orig_ = $height_orig;
     //////////// определение пропорций, под которые подгонять картинку.
     $k = $width_orig / $height_orig;
     $k_out = $width / $height;
     if ($k > $k_out) {
         $width_orig = $height_orig * $k_out;
     } else {
         $height_orig = $width_orig / $k_out;
     }
     ///////////////////////// если картинка не попадает под пропорции, то часть оригинала нужно обрезать.
     $ratio_orig = $width_orig / $height_orig;
     if ($width / $height > $ratio_orig) {
         $width = $height * $ratio_orig;
     } else {
         $height = $width / $ratio_orig;
     }
     //// отцентровать будущую картинку отцентровать по центру оригинала
     $x_shift = ($width_orig_ - $width_orig) / 2;
     $y_shift = ($height_orig_ - $height_orig) / 2;
     $image_p = imagecreatetruecolor($width, $height);
     switch (exif_imagetype($absPathSourceFileName)) {
         case IMAGETYPE_JPEG:
             $image = ImageCreateFromJPEG($absPathSourceFileName);
             imagecopyresampled($image_p, $image, 0, 0, $x_shift, $y_shift, $width, $height, $width_orig, $height_orig);
             ImageJPEG($image_p, $absPath . self::$pathToCropImg . $md5Filename . '.' . $imgExt, 87);
             return '/' . self::$pathToCropImg . $md5Filename . '.' . $imgExt;
         case IMAGETYPE_GIF:
             $image = ImageCreateFromGIF($absPathSourceFileName);
             imagecopyresampled($image_p, $image, 0, 0, $x_shift, $y_shift, $width, $height, $width_orig, $height_orig);
             ImageGIF($image_p, $absPath . self::$pathToCropImg . $md5Filename . '.' . $imgExt);
             return '/' . self::$pathToCropImg . $md5Filename . '.' . $imgExt;
         case IMAGETYPE_PNG:
             $image = ImageCreateFromPNG($absPathSourceFileName);
             imagecopyresampled($image_p, $image, 0, 0, $x_shift, $y_shift, $width, $height, $width_orig, $height_orig);
             ImagePNG($image_p, $absPath . self::$pathToCropImg . $md5Filename . '.' . $imgExt);
             return '/' . self::$pathToCropImg . $md5Filename . '.' . $imgExt;
         case IMAGETYPE_WBMP:
             $image = ImageCreateFromWBMP($absPathSourceFileName);
             imagecopyresampled($image_p, $image, 0, 0, $x_shift, $y_shift, $width, $height, $width_orig, $height_orig);
             ImageWBMP($image_p, $absPath . self::$pathToCropImg . $md5Filename . '.' . $imgExt);
             return '/' . self::$pathToCropImg . $md5Filename . '.' . $imgExt;
         default:
             return $filename;
     }
 }
Exemple #7
0
            $im = @ImageCreateFromPNG($tmpfname);
        } elseif (ereg(".wbmp\$", $remote_file) || ereg(".WBMP\$", $remote_file)) {
            $im = @ImageCreateFromWBMP($tmpfname);
        }
        if (!$im) {
            unlink($tmpfname);
            // delete temporary file
            exit;
            // could not create image from file
        }
        if ($_SESSION['img_ml'] == HAW_HTML) {
            header("content-type: image/png");
            ImagePng($im);
        } else {
            header("content-type: image/vnd.wap.wbmp");
            ImageWBMP($im);
        }
        unlink($tmpfname);
        // delete temporary file
        exit;
    } else {
        // "normal" proxy request: init session variables
        session_register('img_ml');
    }
}
// START OF HAWXY MAIN PART
// init stack to hold received XML tags
$tag_stack = new HAX_tagstack();
// init XML parsing stuff
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
Exemple #8
0
        ImageString($imgerr, 1, 50 - ImageFontWidth(1) * strlen($filename) / 2, 1, $_GET["imagedark"], $tc);
        ImageString($imgerr, 1, 50 - ImageFontWidth(1) * strlen($filename) / 2, 10, "does not exist.", $tc);
    }
}
if (isset($error)) {
    $imgh = $imgerr;
}
if (function_exists("imagepng")) {
    Header("Content-type: image/png");
    ImagePNG($imgh);
} elseif (function_exists("imagejpeg")) {
    Header("Content-type: image/jpeg");
    ImageJPEG($imgh, "", 0.5);
} elseif (function_exists("imagewbmp")) {
    Header("Content-type: image/vnd.wap.wbmp");
    ImageWBMP($imgh);
} else {
    die("No image support in this PHP server");
}
if (isset($imgerr)) {
    imagedestroy($imgerr);
}
if (isset($imgh)) {
    imagedestroy($imgh);
}
if (isset($imgdark)) {
    imagedestroy($imgdark);
}
if (isset($imglight)) {
    imagedestroy($imglight);
}
Exemple #9
0
 public function createThumb($dir, $prefix, $max_x = false, $max_y = false, $prefixIsRealName = false, $mode = 'square')
 {
     if (!isset($this->hash)) {
         return FALSE;
     }
     if (!$dir) {
         $dir = dirname($this->file);
     }
     if (!$prefix) {
         $prefix = 't';
     }
     if (!$max_x && !$max_y || intval($max_x) <= 0 && intval($max_y) <= 0) {
         throw new PException('Neither thumbnail max-width nor max-height provided!');
     }
     $size_x = $this->imageSize[0];
     $size_y = $this->imageSize[1];
     // old school
     if (!$max_x || !$max_y) {
         if ($max_x && intval($max_x) > 0 && $size_x) {
             $th_size_x = intval($max_x);
             $th_size_y = intval($size_y * $th_size_x / $size_x);
             $size_x = $th_size_x;
             $size_y = $th_size_y;
         }
         if ($max_y && intval($max_y) > 0 && $size_y > $max_y) {
             $th_size_y = intval($max_y);
             $th_size_x = intval($size_x * $th_size_y / $size_y);
         }
         $startx = 0;
         $starty = 0;
         $size_x = $this->imageSize[0];
         $size_y = $this->imageSize[1];
     } else {
         switch ($mode) {
             case "ratio":
                 if ($max_x / $size_x >= $max_y / $size_y) {
                     $ratio = $max_y / $size_y;
                 } else {
                     $ratio = $max_x / $size_x;
                 }
                 $startx = 0;
                 $starty = 0;
                 break;
             default:
                 if ($size_x >= $size_y) {
                     $startx = ($size_x - $size_y) / 2;
                     $starty = 0;
                     $size_x = $size_y;
                 } else {
                     $starty = ($size_y - $size_x) / 2;
                     $startx = 0;
                     $size_y = $size_x;
                 }
                 if ($max_x >= $max_y) {
                     $ratio = $max_y / $size_y;
                 } else {
                     $ratio = $max_x / $size_x;
                 }
                 break;
         }
         $th_size_x = $size_x * $ratio;
         $th_size_y = $size_y * $ratio;
     }
     switch (intval($this->imageSize[2])) {
         // note: fixed this to use the proper constants. IMG_*** are GD constants, IMAGETYPE_*** are PHP constants.
         // The two DO NOT mix
         case IMAGETYPE_GIF:
             $oldImage = ImageCreateFromGIF($this->file);
             break;
         case IMAGETYPE_JPEG:
             $oldImage = ImageCreateFromJPEG($this->file);
             break;
         case IMAGETYPE_PNG:
             $oldImage = ImageCreateFromPNG($this->file);
             break;
         case IMAGETYPE_WBMP:
             $oldImage = ImageCreateFromWBMP($this->file);
             break;
         default:
             $e = new PException('Image type not supported!');
             $e->addInfo(print_r($this->imageSize, TRUE));
             throw $e;
             break;
     }
     $newImage = ImageCreateTrueColor($th_size_x, $th_size_y);
     imageCopyResampled($newImage, $oldImage, 0, 0, $startx, $starty, $th_size_x, $th_size_y, $size_x, $size_y);
     $newFile = tempnam('Lorem ipsum dolor sit amet', 'thumb');
     switch ($this->imageSize[2]) {
         case IMAGETYPE_GIF:
             ImageTrueColorToPalette($newImage, TRUE, 256);
             ImageGIF($newImage, $newFile);
             $mimetype = 'image/gif';
             break;
         case IMAGETYPE_JPEG:
             ImageJPEG($newImage, $newFile);
             $mimetype = 'image/jpeg';
             break;
         case IMAGETYPE_PNG:
             ImagePNG($newImage, $newFile);
             $mimetype = 'image/png';
             break;
         case IMAGETYPE_WBMP:
             ImageWBMP($newImage, $newFile);
             $mimetype = 'image/wbmp';
             break;
     }
     $dest = $dir . '/' . $prefix;
     if (!$prefixIsRealName) {
         $dest .= $this->hash;
     }
     if (!@copy($newFile, $dest)) {
         return false;
     }
     unlink($newFile);
     return true;
 }
Exemple #10
0
 public static function switchpic($sourFile, $width = 128, $height = 128, $transparent = 0, $backcolor = null, $focus = null)
 {
     /**
      * gener new file name
      * Enter description here ...
      * @var unknown_type
      */
     if ($transparent) {
         $newName = substr($sourFile, 0, strrpos($sourFile, '.')) . '_' . $width . 'x' . $height . ".png";
     } else {
         $newName = substr($sourFile, 0, strrpos($sourFile, '.')) . '_' . $width . 'x' . $height . substr($sourFile, strrpos($sourFile, '.'));
     }
     $dst_width = $width;
     $dst_height = $height;
     $imageInfo = self::getInfo($sourFile);
     switch ($imageInfo["type"]) {
         case 1:
             //gif
             $img = imagecreatefromgif($sourFile);
             break;
         case 2:
             //jpg
             $img = imagecreatefromjpeg($sourFile);
             break;
         case 3:
             //png
             $img = imagecreatefrompng($sourFile);
             break;
         default:
             return 0;
             break;
     }
     if (!$img) {
         return 0;
     }
     //$width  = ($width > $imageInfo["width"]) ? $imageInfo["width"] : $width;
     //$height = ($height > $imageInfo["height"]) ? $imageInfo["height"] : $height;
     $srcW = $imageInfo["width"];
     $srcH = $imageInfo["height"];
     /*
     if ($srcW * $width > $srcH * $height)
     $height = round($srcH * $width / $srcW);
     else
     $width = round($srcW * $height / $srcH);
     */
     if ($focus == 'width') {
         $height = round($srcH * $width / $srcW);
         $dst_height = $height;
     } elseif ($focus == 'height') {
         $width = round($srcW * $height / $srcH);
         $dst_width = $width;
     } else {
         if ($srcW / $width > $srcH / $height) {
             $height = round($srcH * $width / $srcW);
         } else {
             $width = round($srcW * $height / $srcH);
         }
     }
     if (function_exists("imagecreatetruecolor")) {
         $new = imagecreatetruecolor($dst_width, $dst_height);
         $offset_x = ($dst_width - $width) / 2;
         $offset_y = ($dst_height - $height) / 2;
         $backcolor = self::_getbackcolor($new, $backcolor);
         imagefill($new, 0, 0, $backcolor);
         if ($transparent) {
             //set back color transparent
             imagecolortransparent($new, $backcolor);
         }
         ImageCopyResampled($new, $img, $offset_x, $offset_y, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
     } else {
         throw new Exception("gd library doesn't have imagecreatetruecolor function");
         //            $new = imagecreate($dst_width, $dst_height);
         //            $offset_x = ($dst_width-$width) / 2;
         //            $offset_y = ($dst_height-$height) / 2;
         //            ImageCopyResized($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
     }
     //*/
     if (file_exists($newName)) {
         unlink($newName);
     }
     $maketype = strtolower(substr(strrchr($newName, "."), 1));
     switch ($maketype) {
         case "jpg":
             ImageJPEG($new, $newName, 100);
             break;
         case "gif":
             ImageGIF($new, $newName);
             break;
         case "png":
             ImagePNG($new, $newName, 9);
             break;
         case "wbmp":
             ImageWBMP($new, $newName);
             break;
         default:
             ImageJPEG($new, $newName);
     }
     ImageDestroy($new);
     ImageDestroy($img);
     chmod($newName, 0777);
     return $newName;
 }
Exemple #11
0
 function PutImage($file = NULL, $type = NULL, $destroy = TRUE)
 {
     global $config;
     if ($file) {
         $path = substr($file, 0, strrpos($file, "/"));
         $filename = substr($file, strrpos($file, "/") + 1, strlen($file));
         $type = substr($filename, strrpos($filename, ".") + 1, 4);
     }
     if ($type == "") {
         $type = "png";
     }
     if ($file) {
         if (!is_writable($path)) {
             return t('Unable to write in directory /\'/%1/\'/', $path);
         }
     } else {
         Header("Content-type: image/{$type}");
     }
     if ($file) {
         switch (strtolower($type)) {
             case "jpeg":
             case "jpg":
                 if (ImageTypes() & IMG_JPG) {
                     ImageJPEG($this->img, $file);
                 }
                 break;
             case "gif":
                 if (ImageTypes() & IMG_GIF) {
                     ImageGIF($this->img, $file);
                 }
                 break;
             case "wbmp":
                 if (ImageTypes() & IMG_WBMP) {
                     ImageWBMP($this->img, $file);
                 }
                 break;
             case "bmp":
                 include_once "ext_scripts/gd/bmp.php";
                 ImageBMP($this->img, $file);
                 break;
             case "ico":
                 include_once "ext_scripts/gd/ico.php";
                 ImageICO($this->img, $file);
                 break;
             case "cur":
                 include_once "ext_scripts/gd/cur.php";
                 ImageCUR($this->img, $file);
                 break;
                 /*				case "ani":
                 					include_once("ext_scripts/gd/ani.php");
                 					ImageANI($this->img, $file);
                 				break;*/
             /*				case "ani":
             					include_once("ext_scripts/gd/ani.php");
             					ImageANI($this->img, $file);
             				break;*/
             default:
                 if (ImageTypes() & IMG_PNG) {
                     ImagePNG($this->img, $file);
                 }
                 break;
         }
         chmod($file, octdec($config["lansuite"]["chmod_file"]));
         // Check filesize. Delete if filesize = 0 (i.e. becaus of exceeded disk quota), so it is tried to be generated on next load
         if (filesize($file) == 0) {
             unlink($file);
         }
     } else {
         switch (strtolower($type)) {
             case "jpeg":
             case "jpg":
                 if (ImageTypes() & IMG_JPG) {
                     ImageJPEG($this->img);
                 }
                 break;
             case "gif":
                 if (ImageTypes() & IMG_GIF) {
                     ImageGIF($this->img);
                 }
                 break;
             case "wbmp":
                 if (ImageTypes() & IMG_WBMP) {
                     ImageWBMP($this->img);
                 }
                 break;
             case "bmp":
                 include_once "ext_scripts/gd/bmp.php";
                 ImageBMP($this->img);
                 break;
             case "ico":
                 include_once "ext_scripts/gd/ico.php";
                 ImageICO($this->img);
                 break;
             case "cur":
                 include_once "ext_scripts/gd/cur.php";
                 ImageCUR($this->img);
                 break;
                 /*				case "ani":
                 					include_once("ext_scripts/gd/ani.php");
                 					ImageANI($this->img);
                 				break;*/
             /*				case "ani":
             					include_once("ext_scripts/gd/ani.php");
             					ImageANI($this->img);
             				break;*/
             default:
                 if (ImageTypes() & IMG_PNG) {
                     ImagePNG($this->img);
                 }
                 break;
         }
     }
     if ($destroy) {
         ImageDestroy($this->img);
     }
 }
Exemple #12
0
 function creatthumb($src_path, $src_name, $thumb_path = 'thumb/')
 {
     $src_img = $src_path . $src_name;
     //源图像为其路径加文件名
     $thumb_img = $src_path . $thumb_path . $src_name;
     //缩略图像为其路径加源图像文件名
     if ($this->checkpath($src_path . $thumb_path) == false) {
         $error['flag'] = 0;
         $error['tip'] = '缩略图存放目录不存在且无法创建';
         return $error;
     }
     $error = array();
     //提示信息
     if (file_exists($src_img) == false) {
         //源文件不存在则返回错误信息
         $error['flag'] = 0;
         $error['tip'] = '源图像不存在';
         return $error;
     }
     //临时用宽高度
     $t_width = $this->thumb_width;
     $t_height = $this->thumb_height;
     $src_info = getimagesize($src_img);
     //[0]=>宽,[1]=>高,[2]=>类型 1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,[3]=>文本索引
     //源图像小于或等于缩略图则拷贝源图像作为缩略图
     if ($src_info[0] <= $t_width && $src_info[1] <= $t_height) {
         if (copy($src_img, $src_path . $thumb_path . $src_name) == false) {
             $error['flag'] = 0;
             $error['tip'] = '复制文件失败';
         }
         $error['flag'] = 1;
         $error['tip'] = '创建缩略图成功';
         return $error;
     }
     //按比例计算缩略图大小
     //        if($this->thumb_force==0){
     //	        if ($src_info[0] - $t_width > $src_info[1] - $t_height) {
     //	            $t_height = ($t_width / $src_info[0]) * $src_info[1];
     //	        } else {
     //	            $t_width = ($t_height / $src_info[1]) * $src_info[0];
     //	        }
     //        }
     //创建临时图像
     $fileext = $this->fileext($src_img);
     switch ($fileext) {
         case 'gif':
             $temp_src_img = ImageCreateFromGIF($src_img);
             break;
         case 'jpg':
             $temp_src_img = ImageCreateFromJPEG($src_img);
             break;
         case 'jpeg':
             $temp_src_img = ImageCreateFromJPEG($src_img);
             break;
         case 'png':
             $temp_src_img = ImageCreateFromPNG($src_img);
             break;
         case 'bmp':
             $temp_src_img = ImageCreateFromWBMP($src_img);
             break;
         default:
             $error['flag'] = 0;
             $error['tip'] = '不支持此类图像创建缩略图';
             return $error;
     }
     //创建一个真彩色的缩略图像
     $temp_img = @ImageCreateTrueColor($t_width, $t_height);
     if (function_exists('imagecopyresampled')) {
         @ImageCopyResampled($temp_img, $temp_src_img, 0, 0, 0, 0, $t_width, $t_height, $src_info[0], $src_info[1]);
     } else {
         @ImageCopyResized($temp_img, $temp_src_img, 0, 0, 0, 0, $t_width, $t_height, $src_info[0], $src_info[1]);
     }
     //生成缩略图
     switch ($fileext) {
         case 'gif':
             ImageGIF($temp_img, $thumb_img);
             break;
         case 'jpg':
             ImageJPEG($temp_img, $thumb_img);
             break;
         case 'jpeg':
             ImageJPEG($temp_img, $thumb_img);
             break;
         case 'png':
             ImagePNG($temp_img, $thumb_img);
             break;
         case 'bmp':
             ImageWBMP($temp_img, $thumb_img);
             break;
         default:
             $error['flag'] = 0;
             $error['tip'] = '不支持此类图像创建缩略图';
             return $error;
     }
     //销毁临时图像
     @ImageDestroy($temp_src_img);
     @ImageDestroy($temp_img);
     $error['flag'] = 1;
     $error['tip'] = '创建缩略图成功';
     return $error;
 }