/** * get details of the image by the image url. */ public static function getImageDetails($urlImage) { $info = UniteFunctionsUG::getPathInfo($urlImage); $urlDir = UniteFunctionsUG::getVal($info, "dirname"); if (!empty($urlDir)) { $urlDir = $urlDir . "/"; } $arrInfo = array(); $arrInfo["url_full"] = GlobalsUG::$url_base . $urlImage; $arrInfo["url_dir_image"] = $urlDir; $arrInfo["url_dir_thumbs"] = $urlDir . GlobalsUG::DIR_THUMBS . "/"; $filepath = GlobalsUG::$path_base . urldecode($urlImage); $filepath = realpath($filepath); $path = dirname($filepath) . "/"; $pathThumbs = $path . GlobalsUG::DIR_THUMBS . "/"; $arrInfo["filepath"] = $filepath; $arrInfo["path"] = $path; $arrInfo["path_thumbs"] = $pathThumbs; return $arrInfo; }
/** * Download Image */ public static function downloadImage($filepath, $filename, $mimeType = "") { $contents = file_get_contents($filepath); $filesize = strlen($contents); if ($mimeType == "") { $info = UniteFunctionsUG::getPathInfo($filepath); $ext = $info["extension"]; $mimeType = "image/{$ext}"; } header("Content-Type: {$mimeType}"); header("Content-Disposition: attachment; filename=\"{$filename}\""); header("Content-Length: {$filesize}"); echo $contents; exit; }
/** * make thumbnail from the image, and save to some path * return new path */ public function makeThumb($filepathImage, $pathThumbs, $maxWidth = -1, $maxHeight = -1, $type = "") { //validate input UniteFunctionsUG::validateFilepath($filepathImage, "image not found"); UniteFunctionsUG::validateDir($pathThumbs, "Thumbs folder don't exists."); if ($type == self::TYPE_EXACT || $type == self::TYPE_EXACT_TOP) { if ($maxHeight == -1) { $this->throwError("image with exact type must have height!"); } if ($maxWidth == -1) { $this->throwError("image with exact type must have width!"); } } //get filename $info = UniteFunctionsUG::getPathInfo($filepathImage); $filename = UniteFunctionsUG::getVal($info, "basename"); UniteFunctionsUG::validateNotEmpty($filename, "image filename not given"); //if gd library doesn't exists - output normal image without resizing. if (function_exists("gd_info") == false) { $this->throwError("php must support GD Library"); } if ($maxWidth == -1 && $maxHeight == -1) { $this->throwError("Wrong thumb size"); } if ($maxWidth == -1) { $maxWidth = 1000000; } if ($maxHeight == -1) { $maxHeight = 100000; } $this->filename = $filename; $this->maxWidth = $maxWidth; $this->maxHeight = $maxHeight; $this->type = $type; $this->pathCache = $pathThumbs; $filenameThumb = $this->getThumbFilename(); $filepathNew = $this->pathCache . $filenameThumb; if (file_exists($filepathNew)) { return $filenameThumb; } if ($type == self::TYPE_EXACT || $type == self::TYPE_EXACT_TOP) { $isSaved = $this->cropImageSaveNew($filepathImage, $filepathNew); } else { $isSaved = $this->resizeImageSaveNew($filepathImage, $filepathNew); } if ($isSaved) { return $filenameThumb; } else { return ""; } }