Exemple #1
1
	function openImage($src){
		switch( exif_imagetype($src)){
			case IMAGETYPE_PNG:
				$img = @imagecreatefrompng($src);
				break;
			case IMAGETYPE_GIF:
				$img = @imagecreatefromgif($src);
				break;
			case IMAGETYPE_JPEG:
				$img = @imagecreatefromjpeg($src);
				break;
			case IMAGETYPE_BMP:
				$img = @ImageCreateFromBMP($src);
				break;
			case IMAGETYPE_PSD:
				$img = @imagecreatefrompsd($src);//@
				break;
			default:
				$img = false;
				break;
		}
		return $img;
	}
 public function loadImg($file)
 {
     if (!file_exists($file)) {
         //echo("File not found in loadImg().");
         return false;
     }
     $this->imageSize = getimagesize($file);
     if (!defined("IMAGETYPE_JPG")) {
         define("IMAGETYPE_JPG", IMAGETYPE_JPEG);
     }
     switch ($this->imageSize[2]) {
         case IMAGETYPE_JPG:
             $this->img = imagecreatefromjpeg($file);
             $this->file = $file;
             return true;
         case IMAGETYPE_PNG:
             $this->img = imagecreatefrompng($file);
             imageAlphaBlending($this->img, false);
             imageSaveAlpha($this->img, true);
             $this->file = $file;
             return true;
         case IMAGETYPE_GIF:
             $this->img = imagecreatefromgif($file);
             $this->file = $file;
             break;
         case IMAGETYPE_BMP:
             $this->img = ImageCreateFromBMP($file);
             $this->file = $file;
         default:
             //coreIMG::trace("Unknown file format in loadImg().");
             return false;
     }
 }
Exemple #3
0
function picture_openrandomformat($image, $mime = false){
	if ($mime == false && strtolower(substr($image, 0, 7)) == "http://"){
		$last4 = strtolower(substr($image, -4));
		$last5 = strtolower(substr($image, -5));
		
		if ($last4 == ".jpg" || $last5 == ".jpeg"){
			$mime = "image/jpeg";
		}elseif($last4 == ".gif"){
			$mime = "image/gif";
		}elseif($last4 == ".bmp"){
			$mime = "image/bmp";
		}elseif($last4 == ".png"){
			$mime = "image/png";
		}
	}
	
	if ($mime == false){
		$mime = GetImageSize($image);
		$mime = $mime["mime"];
	}
	
	if ($mime == "image/jpeg"){
		return ImageCreateFromJPEG($image);
	}elseif($mime == "image/gif"){
		$img = ImageCreateFromGIF($image);
	}elseif($mime == "image/bmp"){
		require_once("knj/functions_knj_picture_bmp.php");
		return ImageCreateFromBMP($image);
	}elseif($mime == "image/vnd.wbmp"){
		return ImageCreateFromWBMP($image);
	}elseif($mime == "image/png"){
		$img = ImageCreateFromPNG($image);
	}else{
		return false;
	}
	
	return $img;
}
     $query = "INSERT INTO images (prv,ftpid,userid,filename, tn_filename, filepath, ip, filesize,added) VALUES ({$prv},{$ftpid},{$uid},'{$newFileName}', '{$tnFileName}', '{$url}', '{$uploaderip}', {$filesize},{$date_add})";
     mysql_query($query) or die("Database entry failed.");
     $newID .= "|" . mysql_insert_id();
 }
 if ($file_ext == "jpeg" || $file_ext == "jpg" || $file_ext == "png" || $file_ext == "gif" || $file_ext == "bmp") {
     if ($file_ext == "jpg") {
         $source_id = imagecreatefromjpeg($newFile);
     }
     if ($file_ext == "jpeg") {
         $source_id = imagecreatefromjpeg($newFile);
     } elseif ($file_ext == "png") {
         $source_id = imagecreatefrompng($newFile);
     } elseif ($file_ext == "gif") {
         $source_id = imagecreatefromgif($newFile);
     } elseif ($file_ext == "bmp") {
         $source_id = ImageCreateFromBMP($newFile);
     }
     $true_width = imagesx($source_id);
     $true_height = imagesy($source_id);
     // create thumb
     if ($true_width > $thumbnail_size_max || $true_height > $thumbnail_size_max) {
         $ratio1 = $true_width / $dest_width;
         $ratio2 = $true_height / $dest_height;
         if ($ratio1 > $ratio2) {
             $thumb_w = $dest_width;
             $thumb_h = $true_height / $ratio1;
         } else {
             $thumb_h = $dest_height;
             $thumb_w = $true_width / $ratio2;
         }
         $target_id = imagecreatetruecolor($thumb_w, $thumb_h);
Exemple #5
0
<?php

require_once 'utils.php';
$itemName = $_GET['Name'];
$itemProjectId = $_GET['ProjectId'];
$url = GetItemImageUrl($itemName, $itemProjectId);
// For some reason, reading the bmp file on the homepages server does not
// work, it only reads the first pixel. So we decided to upload PNG files
// which also has the advantage to ensure fast and accurate response.
// Note that should this ever be changed back, the GetItemImageUrl function
// would have to be modified to return the approriate extension
if ($itemName == '' || ($im = ImageCreateFromBMP($url)) === FALSE) {
    $im = imagecreate(1, 1);
    $white = imagecolorallocate($im, 255, 255, 255);
    imagesetpixel($im, 0, 0, $white);
}
//  $im = imagecreatefrompng($url);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
Exemple #6
0
 private function openImage($src)
 {
     if ($this->MemoryLimit) {
         $this->setMemoryForImage($src, $this->TweakFactor);
     }
     switch ($this->info['contenttype'] = exif_imagetype($src)) {
         case IMAGETYPE_PNG:
             $img = imagecreatefrompng($src);
             break;
         case IMAGETYPE_GIF:
             $img = $this->imagecreatefrom_gif($src);
             break;
         case IMAGETYPE_JPEG:
             $img = @imagecreatefromjpeg($src);
             break;
         case IMAGETYPE_BMP:
             $img = @ImageCreateFromBMP($src);
             break;
         case IMAGETYPE_PSD:
             $img = @imagecreatefrompsd($src);
             break;
             //	case IMAGETYPE_ICO:
             //		$img = imagecreatefrom_ico($src);
             //		break;
         //	case IMAGETYPE_ICO:
         //		$img = imagecreatefrom_ico($src);
         //		break;
         default:
             $img = false;
             break;
     }
     return $img;
 }
Exemple #7
0
function GD2_make_thumb_new($max_x, $max_y, $dst_name, $src_file)
{
    $img_info = @getimagesize($src_file);
    $sx = $img_info[0];
    $sy = $img_info[1];
    //썸네일 보다 큰가?
    if ($sx > $max_x && $sy > $max_y) {
        if ($sx > $sy) {
            $thumb_y = ceil($sy * $max_x / $sx);
            $thumb_x = $max_x;
        } else {
            $thumb_x = ceil($sx * $max_y / $sy);
            $thumb_y = $max_y;
        }
    } else {
        if ($sx > $max_x) {
            $thumb_y = ceil($sy * $max_x / $sx);
            $thumb_x = $max_x;
        } else {
            if ($sy > $max_y) {
                $thumb_x = ceil($sx * $max_y / $sy);
                $thumb_y = $max_y;
            } else {
                $thumb_y = $sy;
                $thumb_x = $sx;
            }
        }
    }
    // JPG 파일인가?
    if ($img_info[2] == "2" or 1) {
        $_dq_tempFile = basename($src_file);
        //파일명 추출
        $_dq_tempDir = str_replace($_dq_tempFile, "", $src_file);
        //경로 추출
        $_dq_tempFile = $dst_name;
        //경로 + 새 파일명 생성
        $_create_thumb_file = true;
        /*
         if (file_exists($_dq_tempFile)) { //섬네일 파일이 이미 존제한다면 이미지의 사이즈 비교
        $old_img=@getimagesize($_dq_tempFile);
        if($old_img[0] != $thumb_x) $_create_thumb_file = true; else $_create_thumb_file = false;
        if($old_img[1] != $thumb_y) $_create_thumb_file = true; else $_create_thumb_file = false;
        }
        */
        if ($_create_thumb_file) {
            // 복제
            if ($img_info[2] == "1") {
                $src_img = ImageCreateFromgif($src_file);
            }
            if ($img_info[2] == "2") {
                $src_img = ImageCreateFromjpeg($src_file);
            }
            if ($img_info[2] == "3") {
                $src_img = ImageCreateFrompng($src_file);
            }
            if ($img_info[2] == "16") {
                $src_img = imagecreatefromwxbm($src_file);
            }
            if ($img_info[2] == "5") {
                $src_img = imagecreatefromwbmp($src_file);
            }
            if ($img_info[2] == "6") {
                $src_img = ImageCreateFromBMP($src_file);
            }
            if (!$src_img) {
                $src_img = imagecreatefromjpeg($src_file);
            }
            $dst_img = ImageCreateTrueColor($thumb_x, $thumb_y);
            ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_x, $thumb_y, $sx, $sy);
            Imagejpeg($dst_img, $_dq_tempFile, 100);
            // 메모리 초기화
            ImageDestroy($dst_img);
            ImageDestroy($src_img);
        }
    }
}
Exemple #8
0
    $targ_w = $_POST['w'];
    $targ_h = $_POST['h'];
    $src = $directory . $image;
    exif_imagetype($src);
    if (exif_imagetype($src) == 2) {
        header('Content-type: image/jpeg');
        $img_r = imagecreatefromjpeg($src);
        $dst_r = ImageCreateTrueColor($targ_w, $targ_h);
        imagecopyresampled($dst_r, $img_r, 0, 0, $_POST['x'], $_POST['y'], $targ_w, $targ_h, $_POST['w'], $_POST['h']);
        imagejpeg($dst_r, $uploadingDirectory . "q_" . $_SERVER['REQUEST_TIME'] . "_" . $image, 100);
        echo json_encode("q_" . $_SERVER['REQUEST_TIME'] . "_" . $image);
    } else {
        if (exif_imagetype($src) == 6) {
            //.bmp
            header('Content-type: image/bmp');
            $img_r = ImageCreateFromBMP($src);
            $dst_r = imagecreatetruecolor($targ_w, $targ_h);
            imagecopyresampled($dst_r, $img_r, 0, 0, $_POST['x'], $_POST['y'], $targ_w, $targ_h, $_POST['w'], $_POST['h']);
            imagejpeg($dst_r, $uploadingDirectory . "q_" . $_SERVER['REQUEST_TIME'] . "_" . $image, 100);
            echo json_encode("q_" . $_SERVER['REQUEST_TIME'] . "_" . $image);
        } else {
            echo json_encode("Image type not supported");
        }
    }
});
/* Crop Image */
/**************** RESTful Mongo DATABASE HANDLING ***************/
$app->get('/:database/:table', function ($database, $table) use($page, $skip, $pageSize, $serverFiltering, $serverSorting, $con) {
    $db = $con->{$database};
    $collection = $db->{$table};
    $query = array();
 /**
  * Method to set the image to be resized
  * @param string $sourceFile Path of the Image to be resized
  */
 function setImg($sourceFile)
 {
     // Check if File Exists
     if (file_exists($sourceFile)) {
         // Get Image Type
         $imagetype = $this->getImageType($sourceFile);
         // Default set to True
         $this->canCreateFromSouce = TRUE;
         // Set Image Type to Global Variable
         $this->filetype = $imagetype;
         switch ($imagetype) {
             // PHP can only create thumbnails from GIF, JPG, PNG, WBMP and XBM formats
             // For all others, it will return a 100x100 image that says, unable to create thumbnail
             case 'gif':
                 $this->image = imagecreatefromgif($sourceFile);
                 break;
             case 'jpg':
                 $this->image = imagecreatefromjpeg($sourceFile);
                 break;
             case 'png':
                 $this->image = imagecreatefrompng($sourceFile);
                 break;
             case 'wbmp':
                 $this->image = imagecreatefromwbmp($sourceFile);
                 break;
             case 'xbm':
                 $this->image = imagecreatefromxbm($sourceFile);
                 break;
             case 'bmp':
                 $this->image = ImageCreateFromBMP($sourceFile);
                 break;
             case 'psd':
                 $this->image = imagecreatefrompsd($sourceFile);
                 break;
             default:
                 // Cannot create from source
                 $this->canCreateFromSouce = FALSE;
                 // Create Blank Image with White Background
                 $this->image = imagecreatetruecolor(100, 100);
                 $bgc = imagecolorallocate($this->image, 255, 255, 255);
                 imagefilledrectangle($this->image, 0, 0, 100, 100, $bgc);
                 break;
         }
     } else {
         return FALSE;
     }
 }
Exemple #10
0
 function OpenImage($filename)
 {
     if (!file_exists($filename)) {
         return 0;
     }
     $type = strtolower(substr($filename, strrpos($filename, ".") + 1, 4));
     switch ($type) {
         default:
             return 0;
             break;
         case "png":
             if (ImageTypes() & IMG_PNG) {
                 $img_src = ImageCreateFromPNG($filename);
             }
             break;
         case "jpeg":
         case "jpg":
             if (ImageTypes() & IMG_JPG) {
                 $img_src = ImageCreateFromJPEG($filename);
             }
             break;
         case "gif":
             if (ImageTypes() & IMG_GIF) {
                 $img_src = ImageCreateFromGIF($filename);
             }
             break;
         case "wbmp":
             if (ImageTypes() & IMG_WBMP) {
                 $img_src = ImageCreateFromWBMP($filename);
             }
             break;
         case "bmp":
             include_once "ext_scripts/gd/bmp.php";
             $img_src = ImageCreateFromBMP($filename);
             break;
         case "ico":
             include_once "ext_scripts/gd/ico.php";
             $img_src = ImageCreateFromICO($filename);
             break;
         case "cur":
             include_once "ext_scripts/gd/cur.php";
             $img_src = ImageCreateFromCUR($filename);
             break;
             /*			case "ani":
             				include_once("ext_scripts/gd/ani.php");
             				$img_src = ImageCreateFromANI($filename);
             			break;*/
     }
     return $img_src;
 }