bos =& $Dippler->backoffice; if (is_numeric($id)) { $this->id = $id; $data = $this->bos->loadImage($this->idXML()); if ($data) { $this->load($data); } } } function view($thumb = false) { $add = ""; if ($thumb) $add = "&thumb=1"; return WWW_ROOT . "images/image.php?id=".$this->id.$add; } function load($data) { $this->name = $data->name[0][0]; $this->type = $data->filetype[0][0]; $this->size = $data->filesize[0][0]; if (isset($data->image[0][0])) $this->image = base64_decode($data->image[0][0]); } function resizeToHeight($height) { $ratio = $height / $this->height; $width = $this->width * $ratio; return $this->resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this->width; $height = $this->height * $ratio; return $this->resize($width,$height); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); if ($this->image_type == IMAGETYPE_GIF) { $new_image = imagecreate($width, $height); } if (($this->image_type == IMAGETYPE_GIF) OR ($this->image_type==IMAGETYPE_PNG)){ imagealphablending($new_image, false); imagesavealpha($new_image, true); $transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127); imagefilledrectangle($new_image, 0, 0, $width, $height, $transparent); } imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height); ob_start(); if ($this->type == "image/jpeg" || $this->type == "image/pjpeg") { imagejpeg($new_image, NULL, 85); } else if ($this->type == "image/gif") { imagegif($new_image); } else if ($this->type == "image/png") { imagepng($new_image); } $contents = ob_get_contents(); ob_end_clean(); imagedestroy($new_image); return $contents; } function upload($file) { $allowed_types = array("image/gif", "image/jpeg", "image/pjpeg", "image/png"); if (in_array($file["type"], $allowed_types) && $file["size"] < 25000000) { if ($file["error"] > 0) { return false; } else { $this->file = $file["tmp_name"]; $this->name = strtolower($file["name"]); $this->type = $file["type"]; $this->size = $file["size"]; $this->image = file_get_contents($file['tmp_name']); $image_info = getimagesize($file["tmp_name"]); $this->image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg($file["tmp_name"]); } elseif( $this->image_type == IMAGETYPE_GIF ) { $this->image = imagecreatefromgif($file["tmp_name"]); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng($file["tmp_name"]); } $this->width = imagesx($this->image); $this->height = imagesy($this->image); if ($this->width > 300 && $this->width >= $this->height) { $this->image = $this->resizeToWidth(300); } else if ($this->height > 200 && $this->height > $this->width) { $this->image = $this->resizeToHeight(200); } else { ob_start(); if ($this->type == "image/jpeg" || $this->type == "image/pjpeg") { imagejpeg($this->image, NULL, 85); } else if ($this->type == "image/gif") { imagegif($this->image); } else if ($this->type == "image/png") { imagepng($this->image); } $this->image = ob_get_contents(); ob_end_clean(); } return true; } } return false; } function idXML() { $data = ""; $data .= ""; $data .= "".$this->id.""; $data .= ""; return $data; } } ?>