| Server IP : 172.67.216.113 / Your IP : 104.23.243.33 [ Web Server : Apache System : Linux cpanel01wh.bkk1.cloud.z.com 2.6.32-954.3.5.lve1.4.59.el6.x86_64 #1 SMP Thu Dec 6 05:11:00 EST 2018 x86_64 User : cp648411 ( 1354) PHP Version : 7.2.34 Disable Function : NONE Domains : 0 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home2/cp648411/public_html/kainumber.com/class_old/ |
Upload File : |
<?php
class imageClass
{
public function image($file_array,$namefolde)
{
if($file_array["error"] == 0)
{
@unlink($namefolde);
$name_img = $file_array["name"];
$arr = explode(".",$name_img);
$type = $arr[1];
//$txt = $arr[0]."_".date("U").".".$type;
$txt = rand().date("U").".".$type;
copy($file_array["tmp_name"],$namefolde.$txt."");
}
return $txt;
}
public function file_up($file_array,$namefolde,$part)
{
if($file_array["error"] == 0)
{
$type = $file_array["type"];
$typearr = explode("/",$type);
$name_img = $file_array["name"];
$arr = explode(".",$name_img);
$type = $arr[1];
$file = substr(str_shuffle('abcdefghjkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 6).".".$type;
$name_file = date("y-m-d-").$file;
//$name = rand().date("U").".".$type;
copy($file_array["tmp_name"],$part.$namefolde."/".$name_file."");
}
return $name_file;
}
public function image_re($file_array,$namefolde,$width,$part)
{
if($file_array["error"] == 0)
{
$type = $file_array["type"];
$typearr = explode("/",$type);
$name_img = $file_array["name"];
$arr = explode(".",$name_img);
$type = $arr[1];
$file = substr(str_shuffle('abcdefghjkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 6).".".$type;
$new_images = date("y-m-d-").$file;
//$name = rand().date("U").".".$type;
$images = $file_array["tmp_name"];
//echo $file_array["tmp_name"],$part.$namefolde."/".$new_images;
//exit;
copy($file_array["tmp_name"],$part.$namefolde."/".$new_images);
if($typearr[1] == 'gif' || $typearr[1] == 'GIF')
{
//$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
$size = GetimageSize($images);
$height=round($width * $size[1] / $size[0]);
$images_orig = ImageCreatefromGif($images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
ImageGif($images_fin,$part.$namefolde."/thumb/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
}
if($typearr[1] == 'jpeg' || $typearr[1] == 'JPEG' || $typearr[1] == 'jpg' || $typearr[1] == 'JPG' )
{
//$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
$size = GetimageSize($images);
$height=round($width * $size[1] / $size[0]);
$images_orig = ImageCreateFromJPEG($images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
ImageJPEG($images_fin,$part.$namefolde."/thumb/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
}
if($typearr[1] == 'png' || $typearr[1] == 'PNG')
{
//$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width * $size[1] / $size[0]);
$images_orig = ImageCreatefromPNG($images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
$background = Imagecolorallocatealpha($images_fin, 255, 255, 255, 127);
Imagecolortransparent($images_fin, $background);
Imagealphablending($images_fin, false);
Imagesavealpha($images_fin, true);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
ImagePNG($images_fin,$part.$namefolde."/thumb/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
}
}
return $new_images;
}
public function croptofit($source_path,$name_table, $desired_width, $desired_height)
{
//
// Add file validation code here
//
if($source_path["error"] == 0)
{
$name_img = $source_path["name"];
$arr = explode(".",$name_img);
$type = $arr[1];
$nameimg_new = rand().date("U").".".$type;
$source_path = $source_path["tmp_name"];
list( $source_width, $source_height, $source_type ) = GetimageSize( $source_path );
if($source_type == 1)
{
$source_gdim = Imagecreatefromgif( $source_path );
}
if($source_type == 2)
{
$source_gdim = ImagecreatefromJPEG( $source_path );
}
if($source_type == 3)
{
$source_gdim = ImagecreatefromPNG( $source_path );
}
$height = round($desired_width * $source_height / $source_width);
/*switch ( $source_type )
{
case IMAGETYPE_GIF:
$source_gdim = Imagecreatefromgif( $source_path );
break;
case IMAGETYPE_JPEG:
$source_gdim = ImagecreatefromJPEG( $source_path );
break;
case IMAGETYPE_PNG:
$source_gdim = ImagecreatefromPNG( $source_path );
break;
}*/
$source_aspect_ratio = $source_width / $source_height;
$desired_aspect_ratio = $desired_width / $desired_height;
if ( $source_aspect_ratio > $desired_aspect_ratio )
{
//
// Triggered when source image is wider
//
$temp_height = $desired_height;
$temp_width = ( int ) ( $desired_height * $source_aspect_ratio );
}
else
{
//
// Triggered otherwise (i.e. source image is similar or taller)
//
$temp_width = $desired_width;
$temp_height = ( int ) ( $desired_width / $source_aspect_ratio );
}
//
// Resize the image into a temporary GD image
//
$temp_gdim = imagecreatetruecolor( $temp_width, $temp_height );
imagecopyresampled(
$temp_gdim,
$source_gdim,
0, 0,
0, 0,
$temp_width, $temp_height,
$source_width, $source_height
);
//
// Copy cropped region from temporary image into the desired GD image
//
$x0 = ( $temp_width - $desired_width ) / 2;
$y0 = ( $temp_height - $desired_height ) / 2;
$desired_gdim = imagecreatetruecolor( $desired_width, $desired_height );
imagecopy(
$desired_gdim,
$temp_gdim,
0, 0,
$x0, $y0,
$desired_width, $desired_height
);
//
// Render the image
// Alternatively, you can save the image in file-system or database
//
if($source_type == 1)
{
$photoX = ImagesX($source_gdim);
$photoY = ImagesY($source_gdim);
$width = $desired_width - $x0;
imagealphablending($desired_gdim, false);
imagesavealpha($desired_gdim,true);
$background = imagecolorallocatealpha($desired_gdim, 255, 255, 255, 127);
imagefilledrectangle($desired_gdim, 0, 0, $desired_width, $desired_height, $background);
imagecopyresampled($desired_gdim, $source_gdim, 0, 0, $x0, 0, $desired_width, $desired_height, $desired_width, $desired_height);
ImageGif($desired_gdim,$nameimg_new);
}
if($source_type == 2)
{
ImageJPEG($desired_gdim,$nameimg_new);
}
if($source_type == 3)
{
$photoX = ImagesX($source_gdim);
$photoY = ImagesY($source_gdim);
$width = $desired_width - $x0;
imagealphablending($desired_gdim, false);
imagesavealpha($desired_gdim,true);
$background = imagecolorallocatealpha($desired_gdim, 255, 255, 255, 127);
imagefilledrectangle($desired_gdim, 0, 0, $desired_width, $desired_height, $background);
imagecopyresampled($desired_gdim, $source_gdim, 0, 0, $x0, 0, $desired_width, $desired_height, $desired_width, $desired_height);
ImagePNG($desired_gdim,$nameimg_new);
}
//
// Add clean-up code here
//
}
return $nameimg_new;
}
}
?>