directory_name = $dir_name; //echo $this->directory_name; //exit; } function set_max_size($max_file = 64613){ $this->max_filesize = $max_file; } function get_file_name(){ return $this->file_name; } function error(){ return $this->error; } function is_ok(){ if(isset($this->error)) return FALSE; else return TRUE; } function set_tmp_name($temp_name){ $this->file_tmp_name = $temp_name; } function set_file_size($file_size){ $this->file_size = $file_size; } function set_file_type($file_type){ $this->file_type = $file_type; } function set_file_name($file){ $this->file_name = $file; $this->full_name = $this->directory_name."/".$this->file_name; } function resize($max_width = 0, $max_height = 0 ){ if(eregi("\.png$",$this->full_name)){ $img = ImageCreateFromPNG ($this->full_name); } if(eregi("\.(jpg|jpeg)$",$this->full_name)){ $img = ImageCreateFromJPEG ($this->full_name); } if(eregi("\.gif$",$this->full_name)){ $img = ImageCreateFromGif ($this->full_name); } $FullImage_width = imagesx ($img); $FullImage_height = imagesy ($img); if(isset($max_width) && isset($max_height) && $max_width != 0 && $max_height != 0){ $new_width = $max_width; $new_height = $max_height; }else if(isset($max_width) && $max_width != 0){ $new_width = $max_width; $new_height = ((int)($new_width * $FullImage_height) / $FullImage_width); }else if(isset($max_height) && $max_height != 0){ $new_height = $max_height; $new_width = ((int)($new_height * $FullImage_width) / $FullImage_height); }else{ $new_height = $FullImage_height; $new_width = $FullImage_width; } /* $ratio = ( $FullImage_width > $max_width ) ? (real)($max_width / $FullImage_width) : 1 ; $new_width = ((int)($FullImage_width * $ratio)); //full size width $new_height = ((int)($FullImage_height * $ratio)); //full size height $ratio = ( $new_height > $max_height ) ? (real)($max_height / $new_height) : 1 ; $new_width = ((int)($new_width * $ratio)); //mid size width $new_height = ((int)($new_height * $ratio)); //mid size height */ $full_id = ImageCreateTrueColor ( $new_width , $new_height ); ImageCopyResampled ( $full_id, $img, 0,0,0,0, $new_width, $new_height, $FullImage_width, $FullImage_height ); if(eregi("\.(jpg|jpeg)$",$this->full_name)) { $full = ImageJPEG( $full_id, $this->full_name,100); } if(eregi("\.png$",$this->full_name)) { $full = ImagePNG( $full_id, $this->full_name); } if(eregi("\.gif$",$this->full_name)) { $full = ImageGIF($full_id, $this->full_name); } ImageDestroy( $full_id ); unset($max_width); unset($max_height); } function start_copy(){ if (!empty($this->directory_name)) $destination = $this->full_name; else $destination = $this->file_name; $this->file_name = rand(111111,999999)."_".$this->file_name; if (!empty ($this->directory_name) ) $destination = $this->directory_name."/".$this->file_name; else $destination = $this->file_name; if(!is_uploaded_file($this->file_tmp_name)){ $this->error = "File ".$this->file_tmp_name." is not uploaded correctly."; return false; } if (@move_uploaded_file ($this->file_tmp_name,$destination)){ $this->error = "Impossible to copy ".$this->file_name." from $userfile to destination directory."; return true; } return false; } function set_thumbnail_name($thumbname){ if(eregi("\.png$",$this->full_name)) $this->thumb_name = $this->directory_name."/".$thumbname.".png"; if(eregi("\.(jpg|jpeg)$",$this->full_name)) $this->thumb_name = $this->directory_name."/".$thumbname.".jpg"; if(eregi("\.gif$",$this->full_name)) $this->thumb_name = $this->directory_name."/".$thumbname.".gif"; } function create_thumbnail(){ if (!copy($this->full_name, $this->thumb_name)){ echo "
".$this->full_name.", ".$this->thumb_name."
"; echo "failed to copy $file...
\n"; } } function set_thumbnail_size($max_width = 0, $max_height = 0 ){ if(eregi("\.png$",$this->thumb_name)){ $img = ImageCreateFromPNG ($this->thumb_name); } if(eregi("\.(jpg|jpeg)$",$this->thumb_name)){ $img = ImageCreateFromJPEG ($this->thumb_name); } if(eregi("\.gif$",$this->thumb_name)){ $img = ImageCreateFromGif ($this->thumb_name); } $FullImage_width = imagesx ($img); $FullImage_height = imagesy ($img); if(isset($max_width) && isset($max_height) && $max_width != 0 && $max_height != 0){ $new_width = $max_width; $new_height = $max_height; }else if(isset($max_width) && $max_width != 0){ $new_width = $max_width; $new_height = ((int)($new_width * $FullImage_height) / $FullImage_width); }else if(isset($max_height) && $max_height != 0){ $new_height = $max_height; $new_width = ((int)($new_height * $FullImage_width) / $FullImage_height); }else { $new_height = $FullImage_height; $new_width = $FullImage_width; } $full_id = ImageCreateTrueColor ( $new_width , $new_height ); ImageCopyResampled ( $full_id, $img, 0,0,0,0, $new_width, $new_height, $FullImage_width, $FullImage_height ); if(eregi("\.(jpg|jpeg)$",$this->thumb_name)){ $full = ImageJPEG( $full_id, $this->thumb_name,100); } if(eregi("\.png$",$this->thumb_name)){ $full = ImagePNG( $full_id, $this->thumb_name); } if(eregi("\.gif$",$this->thumb_name)){ $full = ImageGIF($full_id, $this->thumb_name); } ImageDestroy( $full_id ); unset($max_width); unset($max_height); } function imageResize($width, $height, $target, $tmpName, $name, $save) { if ($width > $target) { $percentage = ($target / $width); $newwidth = round($width * $percentage); $newheight = round($height * $percentage); $imageResized = imagecreatetruecolor($newwidth,$newheight); $bg = imagecolorallocate ( $imageResized, 255, 255, 255 ); imagefill($imageResized, 0, 0, $bg ); if(eregi("\.(jpg|jpeg)$",$this->full_name)) { $imageTmp = @imagecreatefromjpeg ("/var/www/vhosts/laartmachine.com/httpdocs/public/upload_images/$name"); } if(eregi("\.png$",$this->full_name)) { $imageTmp = @imagecreatefrompng ("/var/www/vhosts/laartmachine.com/httpdocs/public/upload_images/$name"); } if(eregi("\.gif$",$this->full_name)) { $imageTmp = @imagecreatefromgif ("/var/www/vhosts/laartmachine.com/httpdocs/public/upload_images/$name"); } $save = $save."/".$name; imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); if(eregi("\.(jpg|jpeg)$",$this->full_name)) { imagejpeg($imageResized, $save, 100); } if(eregi("\.png$",$this->full_name)) { imagepng($imageResized, $save, 100); } if(eregi("\.gif$",$this->full_name)) { imagegif($imageResized, $save, 100); } }else { $save = $save."/".$name; copy("/var/www/vhosts/laartmachine.com/httpdocs/public/upload_images/$name",$save); //copy("/home/txstyle/public_html/images/original/$name",$save); } //gets the new value and applies the percentage, then rounds the value } } ?>