/* Seetings needs to be done */
$file = File Name which you created using timestamp
$photos_dir = Directory Path of the file Original files Stored Path
$thumbs_dir = Directory Path where the thumb photos to be stored
$square_size = Width of the file, You can specifiy the width here ex: 100px
set_thumb($file, $photos_dir,$thumbs_dir, $square_size, $quality=100);
function set_thumb($file, $photos_dir,$thumbs_dir, $square_size, $quality=100) {
//check if thumb exists
if (!file_exists($thumbs_dir.”/”.$file)) {
//get image info
list($width, $height, $type, $attr) = getimagesize($photos_dir.”/”.$file);
//set dimensions
if($width> $height) {
$width_t=$square_size;
//respect the ratio
$height_t=round($height/$width*$square_size);
//set the offset
$off_y=ceil(($width_t-$height_t)/2);
$off_x=0;
} elseif($height> $width) {
$height_t=$square_size;
$width_t=round($width/$height*$square_size);
$off_x=ceil(($height_t-$width_t)/2);
$off_y=0;
}
else {
$width_t=$height_t=$square_size;
$off_x=$off_y=0;
}
$system=explode$file = File Name which you created using timestamp
$photos_dir = Directory Path of the file Original files Stored Path
$thumbs_dir = Directory Path where the thumb photos to be stored
$square_size = Width of the file, You can specifiy the width here ex: 100px
set_thumb($file, $photos_dir,$thumbs_dir, $square_size, $quality=100);
function set_thumb($file, $photos_dir,$thumbs_dir, $square_size, $quality=100) {
//check if thumb exists
if (!file_exists($thumbs_dir.”/”.$file)) {
//get image info
list($width, $height, $type, $attr) = getimagesize($photos_dir.”/”.$file);
//set dimensions
if($width> $height) {
$width_t=$square_size;
//respect the ratio
$height_t=round($height/$width*$square_size);
//set the offset
$off_y=ceil(($width_t-$height_t)/2);
$off_x=0;
} elseif($height> $width) {
$height_t=$square_size;
$width_t=round($width/$height*$square_size);
$off_x=ceil(($height_t-$width_t)/2);
$off_y=0;
}
else {
$width_t=$height_t=$square_size;
$off_x=$off_y=0;
}
$system=explode(“.”,$file);
$fileName = $photos_dir.”/”.$file;
if (preg_match(“/jpg|jpeg/”,$system[1])){$thumb=imagecreatefromjpeg($fileName);}
if (preg_match(“/gif/”,$system[1])){$thumb=imagecreatefromgif($fileName);}
if (preg_match(“/png/”,$system[1])){$thumb=imagecreatefrompng($fileName);}
// $thumb=imagecreatefromjpeg($photos_dir.”/”.$file);
$thumb_p = imagecreatetruecolor($square_size, $square_size);
//default background is black
$bg = imagecolorallocate ( $thumb_p, 255, 255, 255 );
imagefill ( $thumb_p, 0, 0, $bg );
imagecopyresampled($thumb_p, $thumb, $off_x, $off_y, 0, 0, $width_t, $height_t, $width, $height);
imagejpeg($thumb_p,$thumbs_dir.”/”.$file,$quality);
}
}(“.”,$file);
$fileName = $photos_dir.”/”.$file;
if (preg_match(“/jpg|jpeg/”,$system[1])){$thumb=imagecreatefromjpeg($fileName);}
if (preg_match(“/gif/”,$system[1])){$thumb=imagecreatefromgif($fileName);}
if (preg_match(“/png/”,$system[1])){$thumb=imagecreatefrompng($fileName);}
// $thumb=imagecreatefromjpeg($photos_dir.”/”.$file);
$thumb_p = imagecreatetruecolor($square_size, $square_size);
//default background is black
$bg = imagecolorallocate ( $thumb_p, 255, 255, 255 );
imagefill ( $thumb_p, 0, 0, $bg );
imagecopyresampled($thumb_p, $thumb, $off_x, $off_y, 0, 0, $width_t, $height_t, $width, $height);
imagejpeg($thumb_p,$thumbs_dir.”/”.$file,$quality);
}
}
$file = File Name which you created using timestamp
$photos_dir = Directory Path of the file Original files Stored Path
$thumbs_dir = Directory Path where the thumb photos to be stored
$square_size = Width of the file, You can specifiy the width here ex: 100px
set_thumb($file, $photos_dir,$thumbs_dir, $square_size, $quality=100);
function set_thumb($file, $photos_dir,$thumbs_dir, $square_size, $quality=100) {
//check if thumb exists
if (!file_exists($thumbs_dir.”/”.$file)) {
//get image info
list($width, $height, $type, $attr) = getimagesize($photos_dir.”/”.$file);
//set dimensions
if($width> $height) {
$width_t=$square_size;
//respect the ratio
$height_t=round($height/$width*$square_size);
//set the offset
$off_y=ceil(($width_t-$height_t)/2);
$off_x=0;
} elseif($height> $width) {
$height_t=$square_size;
$width_t=round($width/$height*$square_size);
$off_x=ceil(($height_t-$width_t)/2);
$off_y=0;
}
else {
$width_t=$height_t=$square_size;
$off_x=$off_y=0;
}
$system=explode$file = File Name which you created using timestamp
$photos_dir = Directory Path of the file Original files Stored Path
$thumbs_dir = Directory Path where the thumb photos to be stored
$square_size = Width of the file, You can specifiy the width here ex: 100px
set_thumb($file, $photos_dir,$thumbs_dir, $square_size, $quality=100);
function set_thumb($file, $photos_dir,$thumbs_dir, $square_size, $quality=100) {
//check if thumb exists
if (!file_exists($thumbs_dir.”/”.$file)) {
//get image info
list($width, $height, $type, $attr) = getimagesize($photos_dir.”/”.$file);
//set dimensions
if($width> $height) {
$width_t=$square_size;
//respect the ratio
$height_t=round($height/$width*$square_size);
//set the offset
$off_y=ceil(($width_t-$height_t)/2);
$off_x=0;
} elseif($height> $width) {
$height_t=$square_size;
$width_t=round($width/$height*$square_size);
$off_x=ceil(($height_t-$width_t)/2);
$off_y=0;
}
else {
$width_t=$height_t=$square_size;
$off_x=$off_y=0;
}
$system=explode(“.”,$file);
$fileName = $photos_dir.”/”.$file;
if (preg_match(“/jpg|jpeg/”,$system[1])){$thumb=imagecreatefromjpeg($fileName);}
if (preg_match(“/gif/”,$system[1])){$thumb=imagecreatefromgif($fileName);}
if (preg_match(“/png/”,$system[1])){$thumb=imagecreatefrompng($fileName);}
// $thumb=imagecreatefromjpeg($photos_dir.”/”.$file);
$thumb_p = imagecreatetruecolor($square_size, $square_size);
//default background is black
$bg = imagecolorallocate ( $thumb_p, 255, 255, 255 );
imagefill ( $thumb_p, 0, 0, $bg );
imagecopyresampled($thumb_p, $thumb, $off_x, $off_y, 0, 0, $width_t, $height_t, $width, $height);
imagejpeg($thumb_p,$thumbs_dir.”/”.$file,$quality);
}
}(“.”,$file);
$fileName = $photos_dir.”/”.$file;
if (preg_match(“/jpg|jpeg/”,$system[1])){$thumb=imagecreatefromjpeg($fileName);}
if (preg_match(“/gif/”,$system[1])){$thumb=imagecreatefromgif($fileName);}
if (preg_match(“/png/”,$system[1])){$thumb=imagecreatefrompng($fileName);}
// $thumb=imagecreatefromjpeg($photos_dir.”/”.$file);
$thumb_p = imagecreatetruecolor($square_size, $square_size);
//default background is black
$bg = imagecolorallocate ( $thumb_p, 255, 255, 255 );
imagefill ( $thumb_p, 0, 0, $bg );
imagecopyresampled($thumb_p, $thumb, $off_x, $off_y, 0, 0, $width_t, $height_t, $width, $height);
imagejpeg($thumb_p,$thumbs_dir.”/”.$file,$quality);
}
}
No comments:
Post a Comment