내가 크기를 사진과 출력을 다시이 스크립트를 가지고 그것 (크기가 너무 큰?) :PHP는 이미지 미리보기가 항상 작동하지 생성
<?php
/**
* Produce a preview of the picture
*
*/
class CtrlImagePreview {
const EXT_DOC = 'doc';
const EXT_FILE = 'file';
const EXT_XLS = 'xls';
/**
* Get the appropriate icon in function of the extension
* @param string $ext
*/
public function icon($ext) {
//put the extension in lowercase
$ext = strtolower($ext);
//check if icon exist
if(file_exists('picture/icon/'.$ext.'.png')) {
//display the approriate icon
$url = 'picture/icon/'.$ext.'.png';
} else {
//display
$url = 'picture/icon/file.png';
}
header("Cache-Control: private, max-age=10800, pre-check=10800");
header("Pragma: private");
header("Expires: " . date(DATE_RFC822,time()+60*60*24*30));
header('Content-Type: image/png');
header('Content-Transfer-Encoding: binary');
readfile($url);
}
/**
* Resize and output preview of the image
* @param File $file
*/
public function resize(File $file) {
header("Cache-Control: private, max-age=10800, pre-check=10800");
header("Pragma: private");
header("Expires: " . date(DATE_RFC822,time()+60*60*24*30));
header('Content-Type: image/png');
header('Content-Transfer-Encoding: binary');
$this->image('../upload/'.$_SESSION['c']->getId().'/'.$file->getProject()->getId().'/'.$file->getName(), true, 45);
}
/**
* NOTE: this function has been imported for image resizing, output mime: image/jpeg
* @param unknown_type $image
* @param unknown_type $crop
* @param unknown_type $size
* @return boolean
*/
private function image($image, $crop = null, $size = null) {
$image = ImageCreateFromString(file_get_contents($image));
if (is_resource($image) === true) {
$x = 0;
$y = 0;
$width = imagesx($image);
$height = imagesy($image);
/*
CROP (Aspect Ratio) Section
*/
if (is_null($crop) === true) {
$crop = array($width, $height);
} else {
$crop = array_filter(explode(':', $crop));
if (empty($crop) === true) {
$crop = array($width, $height);
} else {
if ((empty($crop[0]) === true) || (is_numeric($crop[0]) === false)) {
$crop[0] = $crop[1];
} else if ((empty($crop[1]) === true) || (is_numeric($crop[1]) === false)) {
$crop[1] = $crop[0];
}
}
$ratio = array(0 => $width/$height, 1 => $crop[0]/$crop[1]);
if ($ratio[0] > $ratio[1]) {
$width = $height * $ratio[1];
$x = (imagesx($image) - $width)/2;
}
else if ($ratio[0] < $ratio[1]) {
$height = $width/$ratio[1];
$y = (imagesy($image) - $height)/2;
}
}
/*
Resize Section
*/
if (is_null($size) === true) {
$size = array($width, $height);
}
else {
$size = array_filter(explode('x', $size));
if (empty($size) === true) {
$size = array(imagesx($image), imagesy($image));
} else {
if ((empty($size[0]) === true) || (is_numeric($size[0]) === false)) {
$size[0] = round($size[1] * $width/$height);
} else if ((empty($size[1]) === true) || (is_numeric($size[1]) === false)) {
$size[1] = round($size[0] * $height/$width);
}
}
}
$result = ImageCreateTrueColor($size[0], $size[1]);
if (is_resource($result) === true) {
ImageSaveAlpha($result, true);
ImageAlphaBlending($result, true);
ImageFill($result, 0, 0, ImageColorAllocate($result, 255, 255, 255));
ImageCopyResampled($result, $image, 0, 0, $x, $y, $size[0], $size[1], $width, $height);
ImageInterlace($result, true);
Imagepng($result, null, 0);
}
}
return false;
}
}
?>
이 스크립트 때로는 때로는하지 작동하는지 그것의 문제, 그리고 큰 이미지에서 작동하지 않는 것 같습니다 (내 서버에서만, 로컬 모드에서는 괜찮습니다!). 여기
이 스크립트에 의해 생성 된 사진입니다 :
예 저는 메모리 제한을 256MB로 늘리려고했지만 여전히 작동하지 않습니다 ...;) 감사합니다. –