function createThumb($iTSize, $bSquare = true, $bForce = false, $strThumbPath = false) { if (!$strThumbPath) { $objThumb = new PImage(CACHE_DIR . "thumbnails/" . $iTSize . "x" . $iTSize . "/" . $this->getRelativePath()); } else { $objThumb = new PImage($strThumbPath); } //if objThumb exists if (is_file($objThumb->path)) { if (!$bForce) { return $objThumb; } else { if (!$objThumb->Delete()) { return false; } } } //create the directory $oDirParent = new PDir($objThumb->getParentPath()); if (!is_dir($oDirParent->path) && !$oDirParent->mkdir()) { return false; } if (!$this->Copy($this->getName(), $oDirParent->path)) { return false; } if (!$objThumb->ResizeMax($iTSize, $bSquare)) { $objThumb->Delete(); //if error occured while resizing thumb, delete it. return false; } return $objThumb; }
function getMimeIconUrl($thumb_size) { $strThumbFile = $this->getParentPath() . SLASH . 'images' . SLASH . $this->getNameWithoutExt() . '.gif'; if (is_file($strThumbFile)) { require SITE_PATH . 'core/lib/pimage.php'; $oThumb = new PImage($strThumbFile); return $oThumb->getMimeIconUrl($thumb_size); } return parent::getMimeIconUrl($thumb_size); }
function images_tools_extrapage_imagestoolsresize($strPage, &$site) { if ($strPage != 'imagestoolsresize.php') { return false; } require SITE_PATH . 'core/lib/pimage.php'; if (!isset($_GET['img']) || !isset($_GET['width']) || !isset($_GET['height'])) { return false; } $strImgUrl = urldecode($_GET['img']); if (strstr($strImgUrl, '..') !== FALSE) { return false; } //check that image is a sub file of POLLEN MEDIAS directory if (!($oDirUpload = getFileObjectAndFind(MEDIAS_PATH))) { return false; } if (strstr($strImgUrl, $oDirUpload->getUrl()) === FALSE) { return false; } $strImgUrl = str_replace($oDirUpload->getUrl(), '', $strImgUrl); if (!($oImage = getFileObjectAndFind($oDirUpload->path . SLASH . str_replace('/', SLASH, $strImgUrl)))) { return false; } $iWidth = $_GET['width']; $iHeight = $_GET['height']; //generate the image resized, first copy the original image, then generate the resized image $oImageResize = new PImage(CACHE_DIR . 'thumbnails' . SLASH . $iWidth . 'x' . $iHeight . SLASH . $oImage->getRelativePath()); //create resized image if not exits if (!is_file($oImageResize->path)) { if (!is_dir($oImageResize->getParentPath())) { $oDir = new PDir($oImageResize->getParentPath()); if (!$oDir->mkdir()) { return false; } } if (!$oImage->Copy($oImageResize->getName(), $oImageResize->getParentPath())) { return false; } if (!$oImageResize->Resize($iWidth, $iHeight)) { return false; } } //at this point image must exists, if not return if (!is_file($oImageResize->path)) { return false; } //just set the header and read the image header('Content-type: image/' . $oImage->getExtension()); readfile($oImageResize->path); return true; }
function resizeimage() { require SITE_PATH . 'core/lib/pimage.php'; if (!isset($_POST['FILE_RELATIVE_PATH'])) { return setError('Internal error in resize image, FILE_RELATIVE_PATH is not set'); } if (!isset($_POST['NEW_SIZE'])) { return setError('Internal error in resize image, NEW_SIZE is not set'); } $iNewSize = intval($_POST['NEW_SIZE']); if ($iNewSize < 100 || $iNewSize > 2048) { return setError(_('Size value is not valid.')); } $oImage = new PImage(SITE_PATH . urljsdecode($_POST['FILE_RELATIVE_PATH'])); if (!is_file($oImage->path)) { return setError('Internal error in resize image, object image not found.'); } if (!$oImage->is_image()) { return setError('The file is not an image'); } if (!$oImage->ResizeMax($iNewSize)) { return false; } return true; }