php -------------------- -------------------- -------------------- ---

  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
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
<?php
/*
+----------------------------------------------------------------------+
| ThumbnaiI Image v.: 0.1 (05.12.2006) |
+----------------------------------------------------------------------+
| Generate thumbnail images |
+----------------------------------------------------------------------+
| Author: Stigmat <multzone@inbox.ru> |
+----------------------------------------------------------------------+
*/
class thumbnail_images {
// get
var $PathImgOld;
var $PathImgNew;
var $NewWidth;
var $NewHeight;
// tmp
var $mime;
function imagejpeg_new ($NewImg,$path_img) {
if ($this->mime == 'image/jpeg' or $this->mime == 'image/pjpeg') imagejpeg($NewImg,$path_img);
elseif ($this->mime == 'image/gif') imagegif($NewImg,$path_img);
elseif ($this->mime == 'image/png') imagepng($NewImg,$path_img);
else return(false);
return(true);
}
function imagecreatefromjpeg_new($path_img) {
if ($this->mime == 'image/jpeg' or $this->mime == 'image/pjpeg') $OldImg=imagecreatefromjpeg($path_img);
elseif ($this->mime == 'image/gif') $OldImg=imagecreatefromgif($path_img);
elseif ($this->mime == 'image/png') $OldImg=imagecreatefrompng($path_img);
else return(false);
return($OldImg);
}
function create_thumbnail_images() {
$PathImgOld = $this->PathImgOld;
$PathImgNew = $this->PathImgNew;
$NewWidth = $this->NewWidth;
$NewHeight = $this->NewHeight;
$Oldsize = @getimagesize($PathImgOld);
$this->mime = $Oldsize['mime'];
$OldWidth = $Oldsize[0];
$OldHeight = $Oldsize[1];
if ($NewHeight=='' and $NewWidth!='') {
$NewHeight = ceil(($OldHeight*$NewWidth)/$OldWidth);
}
elseif ($NewWidth=='' and $NewHeight!='') {
$NewWidth = ceil(($OldWidth*$NewHeight)/$OldHeight);
}
elseif ($NewHeight=='' and $NewWidth=='') {
return(false);
}
$OldHeight_castr = ceil(($OldWidth*$NewHeight)/$NewWidth);
$castr_bottom = ($OldHeight-$OldHeight_castr)/2;
$OldWidth_castr = ceil(($OldHeight*$NewWidth)/$NewHeight);
$castr_right = ($OldWidth-$OldWidth_castr)/2;
if ($castr_bottom>0) {
$OldWidth_castr = $OldWidth;
$castr_right = 0;
}
elseif ($castr_right>0) {
$OldHeight_castr = $OldHeight;
$castr_bottom = 0;
}
else {
$OldWidth_castr = $OldWidth;
$OldHeight_castr = $OldHeight;
$castr_right = 0;
$castr_bottom = 0;
}
$OldImg=$this->imagecreatefromjpeg_new($PathImgOld);
if ($OldImg) {
$NewImg_castr=imagecreatetruecolor($OldWidth_castr,$OldHeight_castr);
if ($NewImg_castr) {
imagecopyresampled($NewImg_castr,$OldImg,0,0,$castr_right,$castr_bottom,$OldWidth_castr,$OldHeight_castr,$OldWidth_castr,$OldHeight_castr);
$NewImg=imagecreatetruecolor($NewWidth,$NewHeight);
if ($NewImg) {
imagecopyresampled($NewImg,$NewImg_castr,0,0,0,0,$NewWidth,$NewHeight,$OldWidth_castr,$OldHeight_castr);
imagedestroy($NewImg_castr);
imagedestroy($OldImg);
if (!$this->imagejpeg_new($NewImg,$PathImgNew)) return (false);
imagedestroy($NewImg);
}
}
}
else {
return(false);
}
return(true);
}
}
?>