/** * creates the thumbnail and saves it in $this->outputPath * * @return int (WE_THUMB_OK, WE_THUMB_BUILDERROR, WE_THUMB_USE_ORIGINAL or WE_THUMB_NO_GDLIB_ERROR; * @public */ public function createThumb() { echo '<script>console.log(' . json_encode($this->xfocus) . ');</script>'; if (we_base_imageEdit::gd_version() <= 0) { return self::NO_GDLIB_ERROR; } $tmp = explode('.', $this->imagePath); $type = we_base_imageEdit::$GDIMAGE_TYPE['.' . strtolower(end($tmp))]; if ($this->useOriginalSize() && $this->outputFormat == $type) { return self::USE_ORIGINAL; } if (!we_base_imageEdit::is_imagetype_read_supported($type)) { return self::INPUTFORMAT_NOT_SUPPORTED; } $_thumbdir = self::getThumbDirectory(true); if (!file_exists($_thumbdir)) { we_base_file::createLocalFolder($_thumbdir); } $quality = max(10, min(100, intval($this->thumbQuality) * 10)); $outarr = we_base_imageEdit::edit_image($this->imageData ?: WEBEDITION_PATH . '../' . $this->imagePath, $this->outputFormat, WEBEDITION_PATH . '../' . $this->outputPath, $quality, $this->thumbWidth, $this->thumbHeight, $this->thumbRatio, $this->thumbInterlace, $this->xfocus, $yfocus, -1, -1, 0, $this->thumbFitinside); return $outarr[0] ? self::OK : self::BUILDERROR; }
public static function createPreviewThumb($imgSrc, $imgID, $width, $height, &$outputFormat = "jpg", $outputQuality = 75, $tmpName = "") { if (self::gd_version() == 0) { $outputFormat = 'gif'; return ICON_DIR . 'image.gif'; } if (substr($imgSrc, 0, strlen($_SERVER['DOCUMENT_ROOT'])) == $_SERVER['DOCUMENT_ROOT']) { // it is no src, it is a server path $imgSrc = substr($imgSrc, strlen($_SERVER['DOCUMENT_ROOT'])); } $imgSrc = '/' . ltrim($imgSrc, '/'); $_imgPath = $_SERVER['DOCUMENT_ROOT'] . WEBEDITION_DIR . '../' . $imgSrc; $path_parts = pathinfo($_imgPath); if (isset($path_parts['extension']) && ($path_parts['extension'] === 'svg' || $path_parts['extension'] === 'svgz')) { if (file_exists($_imgPath)) { $outputFormat = 'svg-xml'; return $imgSrc; } $outputFormat = 'gif'; return ICON_DIR . 'image.gif'; } if (!file_exists($_imgPath) || !($imagesize = getimagesize($_imgPath))) { $imagesize = array(0, 0); } if ($imagesize[0] > $width || $imagesize[1] > $height) { $_previewDir = WE_THUMB_PREVIEW_PATH; if (!file_exists($_previewDir) || !is_dir($_previewDir)) { we_base_file::createLocalFolder($_previewDir); } $_thumbSrc = $imgID ? WE_THUMB_PREVIEW_DIR . $imgID . '_' . $width . '_' . $height . strtolower($outputFormat) : TEMP_DIR . ($tmpName ?: we_base_file::getUniqueId()) . '.' . strtolower($outputFormat); $_thumbPath = WEBEDITION_PATH . '../' . $_thumbSrc; $_thumbExists = file_exists($_thumbPath); $_imageCreationDate = filemtime($_imgPath); $_thumbCreationDate = $_thumbExists ? filemtime($_thumbPath) : 0; if (!$_thumbExists || $_imageCreationDate > $_thumbCreationDate) { self::edit_image($_imgPath, $outputFormat, $_thumbPath, $outputQuality, $width, $height); } return $_thumbSrc; } return $imgSrc; }