1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| if($_GET['pic']){
$img = new img('upload/'.$_GET['pic']);
//$destination = 'upload/'.$_GET['pic'];
//$img->img($destination);
$img->resize();
$img->show();
}
class img {
var $image = '';
var $temp = '';
function img($sourceFile){
if(file_exists($sourceFile)){
$this->image = ImageCreateFromJPEG($sourceFile);
} else {
$this->errorHandler();
}
return;
}
function resize($width = 220, $height = 135, $aspectradio = true){
$o_wd = imagesx($this->image);
$o_ht = imagesy($this->image);
if(isset($aspectradio)&&$aspectradio) {
$w = round($o_wd * $height / $o_ht);
$h = round($o_ht * $width / $o_wd);
if(($height-$h)<($width-$w)){
$width =& $w;
} else {
$height =& $h;
}
}
$this->temp = imageCreateTrueColor($width,$height);
imageCopyResampled($this->temp, $this->image,
0, 0, 0, 0, $width, $height, $o_wd, $o_ht);
//imagejpeg($this->temp, $destination);
$this->sync();
return;
}
function sync(){
$this->image =& $this->temp;
unset($this->temp);
$this->temp = '';
return;
}
function show(){
$this->_sendHeader();
ImageJPEG($this->image);
return;
}
function _sendHeader(){
header('Content-Type: image/jpeg');
}
function errorHandler(){
echo "error";
exit();
}
function store($file){
ImageJPEG($this->image,$file);
return;
}
function watermark($pngImage, $left = 0, $top = 0){
ImageAlphaBlending($this->image, true);
$layer = ImageCreateFromPNG($pngImage);
$logoW = ImageSX($layer);
$logoH = ImageSY($layer);
ImageCopy($this->image, $layer, $left, $top, 0, 0, $logoW, $logoH);
}
} |
Partager