primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,354 @@
<?php
/**
* @package Phoca Gallery
* @author Jan Pavelka - https://www.phoca.cz
* @copyright Copyright (C) Jan Pavelka https://www.phoca.cz
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 and later
* @cms Joomla
* @copyright Copyright (C) Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Factory;
class PhocaGalleryImage
{
public static function getImageSize($filename, $returnString = 0, $extLink = 0) {
phocagalleryimport('phocagallery.image.image');
phocagalleryimport('phocagallery.path.path');
if ($extLink == 1) {
$fileNameAbs = $filename;
} else {
$path = PhocaGalleryPath::getPath();
$fileNameAbs = Path::clean($path->image_abs . $filename);
if (!File::exists($fileNameAbs)) {
$fileNameAbs = $path->image_abs_front . 'phoca_thumb_l_no_image.png';
}
}
if ($returnString == 1) {
$imageSize = @getimagesize($fileNameAbs);
return $imageSize[0] . ' x '.$imageSize[1];
} else {
return @getimagesize($fileNameAbs);
}
}
public static function getRealImageSize($filename, $size = 'large', $extLink = 0) {
phocagalleryimport('phocagallery.file.thumbnail');
if ($extLink == 1) {
list($w, $h, $type) = @getimagesize($filename);
} else {
$thumbName = PhocaGalleryFileThumbnail::getThumbnailName ($filename, $size);
list($w, $h, $type) = @getimagesize($thumbName->abs);
}
$sizeA = array();
if (isset($w) && isset($h)) {
$sizeA['w'] = $w;
$sizeA['h'] = $h;
} else {
$sizeA['w'] = 0;
$sizeA['h'] = 0;
}
return $sizeA;
}
public static function correctSizeWithRate($width, $height, $corWidth = 100, $corHeight = 100) {
$image['width'] = $corWidth;
$image['height'] = $corHeight;
if ($width > $height) {
if ($width > $corWidth) {
$image['width'] = $corWidth;
$rate = $width / $corWidth;
$image['height'] = $height / $rate;
} else {
$image['width'] = $width;
$image['height'] = $height;
}
} else {
if ($height > $corHeight) {
$image['height'] = $corHeight;
$rate = $height / $corHeight;
$image['width'] = $width / $rate;
} else {
$image['width'] = $width;
$image['height'] = $height;
}
}
return $image;
}
public static function correctSize($imageSize, $size = 100, $sizeBox = 100, $sizeAdd = 0) {
$image['size'] = $imageSize;
if ((int)$image['size'] < (int)$size ) {
$image['size'] = $size;
$image['boxsize'] = (int)$size + (int)$sizeAdd;
} else {
$image['boxsize'] = (int)$image['size'] + (int)$sizeAdd;
}
return $image;
}
public static function correctSwitchSize($switchHeight, $switchWidth) {
$switchImage['height'] = $switchHeight;
$switchImage['centerh'] = ($switchHeight / 2) - 18;
$switchImage['width'] = $switchWidth;
$switchImage['centerw'] = ($switchWidth / 2) - 18;
$switchImage['height'] = $switchImage['height'] + 5;
return $switchImage;
}
/*
* type ... 1 categories, 2 category view
*/
public static function setBoxSize($p, $type = 1) {
$w = 20;
$w2 = 25;
$w3 = 18;
$w4 = 40;
$boxWidth = 0;
$boxSize['width'] = 0;
$boxSize['height'] = 0;
if (isset($p['imagewidth'])) {
$boxSize['width'] = $boxSize['width'] + (int)$p['imagewidth'];
}
if (isset($p['imageheight'])) {
$boxSize['height'] = $boxSize['height'] + (int)$p['imageheight'];
}
if (isset($p['display_name']) && ($p['display_name'] == 1 || $p['display_name'] == 2)) {
$boxSize['height'] = $boxSize['height'] + $w;
}
if ($type == 3) {
$boxSize['height'] = $boxSize['height'] + $w;
return $boxSize;
}
if ( (isset($p['display_rating']) && $p['display_rating'] == 1) || (isset($p['display_rating_img']) && $p['display_rating_img'] > 0)) {
if ($type == 1) {
$boxSize['height'] = $boxSize['height'] + $w4;
} else {
$boxSize['height'] = $boxSize['height'] + $w;
}
}
if (isset($p['displaying_tags_true']) && $p['displaying_tags_true'] == 1) {
$boxSize['height'] = $boxSize['height'] + (int) + $w3;
}
if (isset($p['display_icon_detail']) && $p['display_icon_detail'] == 1) {
$boxWidth = $boxWidth + $w;
}
if (isset($p['display_icon_download']) && (int)$p['display_icon_download'] > 0) {
$boxWidth = $boxWidth + $w;
}
if (isset($p['display_icon_vm']) && $p['display_icon_vm'] == 1) {
$boxWidth = $boxWidth + $w;
}
if (isset($p['start_cooliris']) && $p['start_cooliris'] == 1) {
$boxWidth = $boxWidth + $w;
}
if (isset($p['trash']) && $p['trash'] == 1) {
$boxWidth = $boxWidth + $w;
}
if (isset($p['publish_unpublish']) && $p['publish_unpublish'] == 1) {
$boxWidth = $boxWidth + $w;
}
if (isset($p['display_icon_geo_box']) && $p['display_icon_geo_box'] == 1) {
$boxWidth = $boxWidth + $w;
}
if (isset($p['display_camera_info']) && $p['display_camera_info'] == 1) {
$boxWidth = $boxWidth + $w;
}
if (isset($p['display_icon_extlink1_box']) && $p['display_icon_extlink1_box'] == 1) {
$boxWidth = $boxWidth + $w;
}
if (isset($p['display_icon_extlink2_box']) && $p['display_icon_extlink2_box'] == 1) {
$boxWidth = $boxWidth + $w;
}
if (isset($p['approved_not_approved']) && $p['approved_not_approved'] == 1) {
$boxWidth = $boxWidth + $w;
}
if (isset($p['display_icon_commentimg_box']) && $p['display_icon_commentimg_box'] == 1) {
$boxWidth = $boxWidth + $w;
}
$boxHeightRows = ceil($boxWidth/$boxSize['width']);
$boxSize['height'] = ($w * $boxHeightRows) + $boxSize['height'];
// LAST
if ($type == 1) {
if (isset($p['categories_box_space'])) {
$boxSize['height'] = $boxSize['height'] + (int)$p['categories_box_space'];
}
} else {
if (isset($p['category_box_space'])) {
$boxSize['height'] = $boxSize['height'] + (int)$p['category_box_space'];
}
}
return $boxSize;
}
public static function getPngQuality($thumbQuality) {
if ((int)$thumbQuality < 0) {
$thumbQuality = 0;
}
if ((int)$thumbQuality > 100) {
$thumbQuality = 100;
}
$pngQuality = ($thumbQuality - 100) / 11.111111;
$pngQuality = round(abs($pngQuality));
return $pngQuality;
}
public static function getJpegQuality($jpegQuality) {
if ((int)$jpegQuality < 0) {
$jpegQuality = 0;
}
if ((int)$jpegQuality > 100) {
$jpegQuality = 100;
}
return $jpegQuality;
}
/*
* Transform image (only with html method) for overlib effect e.g.
*
* @param array An array of image size (width, height)
* @param int Rate
* @access public
*/
public static function getTransformImageArray($imgSize, $rate) {
if (isset($imgSize[0]) && isset($imgSize[1])) {
$w = (int)$imgSize[0];
$h = (int)$imgSize[1];
if ($w != 0) {$w = $w/$rate;} // plus or minus should be divided, not null
if ($h != 0) {$h = $h/$rate;}
$wHOutput = array('width' => $w, 'height' => $h, 'style' => 'background: #fff url('.Uri::base(true).'/media/com_phocagallery/images/icon-loading2.gif) 50% 50% no-repeat;');
} else {
$w = $h = 0;
$wHOutput = array();
}
return $wHOutput;
}
/*
* Used for albums or specific images
* Check if it is Picasa or Facebook category or image
* If we ask only on image, the second parameter will be empty and will be ignnored
* If we ask album, first check Picasa album, second check Facebook album
*/
public static function isExtImage($extid, $extfbcatid = '') {
// EXTID (IMAGES): Picasa - yes, Facebook - yes
// EXTID (ALBUMS): Picasa - yes, Facebook - no
if (isset($extid) && $extid != '') {
return true;
}
// EXTFBCATID (IMAGES): Picasa - no, Facebook - no
// EXTFBCATID (ALBUMS): Picasa - no, Facebook - yes
if (isset($extfbcatid) && $extfbcatid != '') {
return true;
}
return false;
}
public static function getImageByImageId($id = 0) {
$db = Factory::getDBO();
$query = ' SELECT a.id, a.title, c.title as category_title'
.' FROM #__phocagallery AS a'
.' LEFT JOIN #__phocagallery_categories AS c ON c.id = a.catid'
.' WHERE a.id = '.(int)$id
.' GROUP BY a.id, a.title, c.title'
.' ORDER BY a.id'
.' LIMIT 1';
$db->setQuery($query);
$image = $db->loadObject();
return $image;
}
public static function updateRealThumbnailSizes($image, $sizes) {
if ($image == '') {
return false;
}
if (empty($sizes)) {
return false;
}
$path = PhocaGalleryPath::getPath();
$file = str_replace($path->image_rel, '', $image);
$extW = '';
if (isset($sizes['l']['w']) && isset($sizes['m']['w']) && isset($sizes['s']['w'])) {
$extW = (int)$sizes['l']['w'].','.(int)$sizes['m']['w'].','.(int)$sizes['s']['w'];
}
$extH = '';
if (isset($sizes['l']['h']) && isset($sizes['m']['h']) && isset($sizes['s']['h'])) {
$extH = (int)$sizes['l']['h'].','.(int)$sizes['m']['h'].','.(int)$sizes['s']['h'];
}
if ($file != '' && $extW != '' && $extH != '') {
$db = Factory::getDBO();
$query = 'UPDATE #__phocagallery'
.' SET extw = '.$db->quote($extW).','
.' exth = '.$db->quote($extH)
.' WHERE filename = '.$db->quote($file);
$db->setQuery($query);
$db->execute();
return true;
}
return false;
}
}
?>

View File

@ -0,0 +1,333 @@
<?php
/**
* @package Phoca Gallery
* @author Jan Pavelka - https://www.phoca.cz
* @copyright Copyright (C) Jan Pavelka https://www.phoca.cz
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 and later
* @cms Joomla
* @copyright Copyright (C) Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Filesystem\File;
jimport( 'joomla.filesystem.folder' );
jimport( 'joomla.filesystem.file' );
phocagalleryimport('phocagallery.path.path');
phocagalleryimport('phocagallery.file.file');
phocagalleryimport('phocagallery.image.image');
phocagalleryimport('phocagallery.utils.utils');
/*
* Obsolete
*/
class PhocaGalleryImageBgImage
{
public static function createBgImage($data, &$errorMsg) {
$params = ComponentHelper::getParams('com_phocagallery') ;
$jfile_thumbs = $params->get( 'jfile_thumbs', 1 );
$jpeg_quality = $params->get( 'jpeg_quality', 85 );
$jpeg_quality = PhocaGalleryImage::getJpegQuality($jpeg_quality);
$webp_quality = $params->get( 'webp_quality', 80 );
$webp_quality = PhocaGalleryImage::getJpegQuality($webp_quality);
$avif_quality = $params->get( 'avif_quality', 80 );
$avif_quality = PhocaGalleryImage::getJpegQuality($avif_quality);
$formatIcon = 'png';
$path = PhocaGalleryPath::getPath();
$fileIn = $fileOut = $path->image_abs_front. $data['image'] .'.'. $formatIcon;
if ($fileIn !== '' && File::exists($fileIn)) {
/*$memory = 8;
$memoryLimitChanged = 0;
$memory = (int)ini_get( 'memory_limit' );
if ($memory == 0) {
$memory = 8;
}
// Try to increase memory
if ($memory < 50) {
ini_set('memory_limit', '50M');
$memoryLimitChanged = 1;
}*/
$imageWidth = $data['iw'];
$imageHeight = $data['ih'];
$completeImageWidth = $imageWidth + 18;
$completeImageHeight = $imageHeight + 18;
$completeImageBackground = $data['sbgc'];
$retangleColor = $data['ibgc'];
$borderColor = $data['ibrdc'];
$shadowColor = $data['iec'];
$effect = $data['ie'];// shadow or glow
$imgX = 6; $imgWX = $imageWidth + 5 + $imgX;// Image Width + space (padding) + Start Position
$imgY = 6; $imgHY = $imageHeight + 5 + $imgY;
$brdX = $imgX - 1; $brdWX = $imgWX + 1;
$brdY = $imgY - 1; $brdHY = $imgHY + 1;
// Crate an image
$img = @imagecreatetruecolor($completeImageWidth, $completeImageHeight);
if (!$img) {
$errorMsg = 'ErrorNoImageCreateTruecolor';
return false;
}
if ($completeImageBackground == '') {
switch($formatIcon) {
case 'jpg':
case 'jpeg':
case 'gif':
$completeImageBackground = '#ffffff';
break;
case 'png':
case 'webp':
case 'avif':
@imagealphablending($img,false);
imagefilledrectangle($img,0,0,$completeImageWidth,$completeImageHeight,imagecolorallocatealpha($img,255,255,255,127));
@imagealphablending($img,true);
break;
}
} else {
$bGClr = PhocaGalleryUtils::htmlToRgb($completeImageBackground);
imagefilledrectangle($img, 0, 0, $completeImageWidth, $completeImageHeight, imagecolorallocate($img, $bGClr[0], $bGClr[1], $bGClr[2]));
}
// Create Retangle
if ($retangleColor != '') {
$rtgClr = PhocaGalleryUtils::htmlToRgb($retangleColor);
$retangle = imagecolorallocate($img, $rtgClr[0], $rtgClr[1], $rtgClr[2]);
}
// Create Border
if ($borderColor != '') {
$brdClr = PhocaGalleryUtils::htmlToRgb($borderColor);
$border = imagecolorallocate($img, $brdClr[0], $brdClr[1], $brdClr[2]);
}
// Effect (shadow,glow)
if ((int)$effect > 0)
if ($shadowColor != '') {
$shdClr = PhocaGalleryUtils::htmlToRgb($shadowColor);
if ((int)$effect == 3) {
$shdX = $brdX - 1;
$shdY = $brdY - 1;
$effectArray = array(55,70,85,100,115);
} else if ((int)$effect == 2) {
$shdX = $brdX + 3;
$shdY = $brdY + 3;
$effectArray = array(50, 70, 90, 110);
} else {
$shdX = $brdX + 3;
$shdY = $brdY + 3;
$effectArray = array(0,0,0,0);
}
$shdWX = $brdWX + 1;
$shdHY = $brdHY + 1;
foreach($effectArray as $key => $value) {
$effectImg = @imagecolorallocatealpha($img, $shdClr[0], $shdClr[1], $shdClr[2],$value);
if (!$effectImg) {
$errorMsg = 'ErrorNoImageColorAllocateAlpha';
return false;
}
imagerectangle($img, $shdX, $shdY, $shdWX, $shdHY, $effectImg);
if ((int)$effect == 3) {
$shdX--;
$shdY--;
} else if ((int)$effect == 2) {
$shdX++;
$shdY++;
} else {
//$shdX++;
//$shdY++;
}
$shdWX++;
$shdHY++;
}
}
// Write Rectangle over the shadow
if ($retangleColor != '') {
imagefilledrectangle($img, $imgX, $imgY, $imgWX, $imgHY, $retangle);
}
if ($borderColor != '') {
imagerectangle($img, $brdX, $brdY, $brdWX, $brdHY, $border);
}
switch($formatIcon) {
case 'jpg':
case 'jpeg':
if (!function_exists('ImageJPEG')) {
$errorMsg = 'ErrorNoJPGFunction';
return false;
}
if ($jfile_thumbs == 1) {
ob_start();
if (!@ImageJPEG($img, NULL, $jpeg_quality)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgJPEGToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgJPEGToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@ImageJPEG($img, $fileOut, $jpeg_quality)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
case 'png' :
if (!function_exists('ImagePNG')) {
$errorMsg = 'ErrorNoPNGFunction';
return false;
}
@imagesavealpha($img, true);
if ($jfile_thumbs == 1) {
ob_start();
if (!@ImagePNG($img, NULL)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgPNGToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgPNGToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@ImagePNG($img, $fileOut)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
case 'gif' :
if (!function_exists('ImageGIF')) {
$errorMsg = 'ErrorNoGIFFunction';
return false;
}
if ($jfile_thumbs == 1) {
ob_start();
if (!@ImageGIF($img, NULL)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgGIFToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgGIFToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@ImageGIF($img, $fileOut)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
case 'webp' :
if (!function_exists('ImageWebp')) {
$errorMsg = 'ErrorNoWEBPFunction';
return false;
}
@imagesavealpha($img, true);
if ($jfile_thumbs == 1) {
ob_start();
if (!@imagewebp($img, NULL, $webp_quality)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgWEBPToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgWEBPToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@imagewebp($img, $fileOut, $webp_quality)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
case 'avif' :
if (!function_exists('ImageAvif')) {
$errorMsg = 'ErrorNoAVIFFunction';
return false;
}
@imagesavealpha($img, true);
if ($jfile_thumbs == 1) {
ob_start();
if (!@imageavif($img, NULL, $avif_quality)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgAVIFToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgAVIFToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@imageavif($img, $fileOut, $webp_quality)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
Default:
$errorMsg = 'ErrorNotSupportedImage';
return false;
break;
}
// free memory
ImageDestroy($img);// Original
/*if ($memoryLimitChanged == 1) {
$memoryString = $memory . 'M';
ini_set('memory_limit', $memoryString);
}*/
return true; // Success
}
$errorMsg = 'Error2';
return false;
}
}
?>

View File

@ -0,0 +1,734 @@
<?php
/**
* @package Phoca Gallery
* @author Jan Pavelka - https://www.phoca.cz
* @copyright Copyright (C) Jan Pavelka https://www.phoca.cz
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 and later
* @cms Joomla
* @copyright Copyright (C) Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
use Joomla\CMS\Factory;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Filesystem\File;
jimport( 'joomla.filesystem.folder' );
jimport( 'joomla.filesystem.file' );
phocagalleryimport('phocagallery.render.renderprocess');
phocagalleryimport('phocagallery.file.file');
phocagalleryimport('phocagallery.image.image');
register_shutdown_function(function(){
$error = error_get_last();
if(null !== $error) {
if (isset($error['type']) && $error['type'] == 1) {
$app = Factory::getApplication();
$app->redirect('index.php?option=com_phocagallery&view=phocagalleryfe&error=1');
return;
}
}
});
class PhocaGalleryImageMagic
{
/**
* need GD library (first PHP line WIN: dl("php_gd.dll"); UNIX: dl("gd.so");
* www.boutell.com/gd/
* interval.cz/clanky/php-skript-pro-generovani-galerie-obrazku-2/
* cz.php.net/imagecopyresampled
* www.linuxsoft.cz/sw_detail.php?id_item=871
* www.webtip.cz/art/wt_tech_php/liquid_ir.html
* php.vrana.cz/zmensovani-obrazku.php
* diskuse.jakpsatweb.cz/
*
* @param string $fileIn Vstupni soubor (mel by existovat)
* @param string $fileOut Vystupni soubor, null ho jenom zobrazi (taky kdyz nema pravo se zapsat :)
* @param int $width Vysledna sirka (maximalni)
* @param int $height Vysledna vyska (maximalni)
* @param bool $crop Orez (true, obrazek bude presne tak velky), jinak jenom Resample (udane maximalni rozmery)
* @param int $typeOut IMAGETYPE_type vystupniho obrazku
* @return bool Chyba kdyz vrati false
*/
public static function imageMagic($fileIn, $fileOut = null, $width = null, $height = null, $crop = null, $typeOut = null, $watermarkParams = array(), $frontUpload = 0, &$errorMsg = '') {
$params = ComponentHelper::getParams('com_phocagallery') ;
$jfile_thumbs = $params->get( 'jfile_thumbs', 1 );
$jpeg_quality = $params->get( 'jpeg_quality', 85 );
$exif_rotate = $params->get( 'exif_rotate', 0 );
$jpeg_quality = PhocaGalleryImage::getJpegQuality($jpeg_quality);
$webp_quality = $params->get( 'webp_quality', 80 );
$webp_quality = PhocaGalleryImage::getJpegQuality($webp_quality);
$avif_quality = $params->get( 'avif_quality', 80 );
$avif_quality = PhocaGalleryImage::getJpegQuality($avif_quality);
$fileWatermark = '';
// While front upload we don't display the process page
if ($frontUpload == 0) {
$stopText = PhocaGalleryRenderProcess::displayStopThumbnailsCreating('processpage');
echo $stopText;
}
// Memory - - - - - - - -
/*$memory = 8;
$memoryLimitChanged = 0;
$memory = (int)ini_get( 'memory_limit' );
if ($memory == 0) {
$memory = 8;
}*/
// - - - - - - - - - - -
if ($fileIn !== '' && File::exists($fileIn)) {
// array of width, height, IMAGETYPE, "height=x width=x" (string)
list($w, $h, $type) = GetImageSize($fileIn);
// Read EXIF data from image file to get the Orientation flag
$exif = null;
if ($exif_rotate == 1) {
if (function_exists('exif_read_data') && $type == IMAGETYPE_JPEG ) {
$exif = @exif_read_data($fileIn);
}
// GetImageSize returns an array of width, height, IMAGETYPE, "height=x width=x" (string)
// The EXIF Orientation flag is examined to determine if width and height need to be swapped, i.e. if the image will be rotated in a subsequent step
if(isset($exif['Orientation']) && !empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8: // will need to be rotated 90 degrees left, so swap order of width and height
list($h, $w, $type) = GetImageSize($fileIn);
break;
case 3: // will need to be rotated 180 degrees so don't swap order of width and height
list($w, $h, $type) = GetImageSize($fileIn);
break;
case 6: // will need to be rotated 90 degrees right, so swap order of width and height
list($h, $w, $type) = GetImageSize($fileIn);
break;
}
}
}
if ($w > 0 && $h > 0) {// we got the info from GetImageSize
// size of the image
if ($width == null || $width == 0) { // no width added
$width = $w;
}
else if ($height == null || $height == 0) { // no height, adding the same as width
$height = $width;
}
if ($height == null || $height == 0) { // no height, no width
$height = $h;
}
// miniaturizing
if (!$crop) { // new size - nw, nh (new width/height)
$scale = (($width / $w) < ($height / $h)) ? ($width / $w) : ($height / $h); // smaller rate
//$scale = $height / $h;
$src = array(0,0, $w, $h);
$dst = array(0,0, floor($w*$scale), floor($h*$scale));
}
else { // will be cropped
$scale = (($width / $w) > ($height / $h)) ? ($width / $w) : ($height / $h); // greater rate
$newW = $width/$scale; // check the size of in file
$newH = $height/$scale;
// which side is larger (rounding error)
if (($w - $newW) > ($h - $newH)) {
$src = array(floor(($w - $newW)/2), 0, floor($newW), $h);
}
else {
$src = array(0, floor(($h - $newH)/2), $w, floor($newH));
}
$dst = array(0,0, floor($width), floor($height));
}
// Watermark - - - - - - - - - - -
if (!empty($watermarkParams) && ($watermarkParams['create'] == 1 || $watermarkParams['create'] == 2)) {
$thumbnailSmall = false;
$thumbnailMedium = false;
$thumbnailLarge = false;
$thumbnailMedium = preg_match("/phoca_thumb_m_/i", $fileOut);
$thumbnailLarge = preg_match("/phoca_thumb_l_/i", $fileOut);
$path = PhocaGalleryPath::getPath();
$fileName = PhocaGalleryFile::getTitleFromFile($fileIn, 1);
// Which Watermark will be used
// If watermark is in current directory use it else use Default
$fileWatermarkMedium = false;
$fileWatermarkLarge = false;
$fileWatermarkMediumPng = str_replace($fileName, 'watermark-medium.png', $fileIn);
$fileWatermarkLargePng = str_replace($fileName, 'watermark-large.png', $fileIn);
$fileWatermarkMediumWebp = str_replace($fileName, 'watermark-medium.webp', $fileIn);
$fileWatermarkLargeWebp = str_replace($fileName, 'watermark-large.webp', $fileIn);
$fileWatermarkMediumAvif = str_replace($fileName, 'watermark-medium.avif', $fileIn);
$fileWatermarkLargeAvif = str_replace($fileName, 'watermark-large.avif', $fileIn);
$fileWatermarkMediumRoot = false;
$fileWatermarkLargeRoot = false;
$fileWatermarkMediumPngRoot = $path->image_abs . 'watermark-medium.png';
$fileWatermarkLargePngRoot = $path->image_abs . 'watermark-large.png';
$fileWatermarkMediumWebpRoot = $path->image_abs . 'watermark-medium.webp';
$fileWatermarkLargeWebpRoot = $path->image_abs . 'watermark-large.webp';
$fileWatermarkMediumAvifRoot = $path->image_abs . 'watermark-medium.avif';
$fileWatermarkLargeAvifRoot = $path->image_abs . 'watermark-large.avif';
if ($type == IMAGETYPE_WEBP) {
if (File::exists($fileWatermarkMediumWebp)) {
$fileWatermarkMedium = $fileWatermarkMediumWebp;
} else if (File::exists($fileWatermarkMediumPng)) {
$fileWatermarkMedium = $fileWatermarkMediumPng;
} else if (File::exists($fileWatermarkMediumAvif)) {
$fileWatermarkMedium = $fileWatermarkMediumAvif;
}
if (File::exists($fileWatermarkMediumWebpRoot)) {
$fileWatermarkMediumRoot = $fileWatermarkMediumWebpRoot;
} else if (File::exists($fileWatermarkMediumPngRoot)) {
$fileWatermarkMediumRoot = $fileWatermarkMediumPngRoot;
} else if (File::exists($fileWatermarkMediumAvifRoot)) {
$fileWatermarkMediumRoot = $fileWatermarkMediumAvifRoot;
}
if (File::exists($fileWatermarkLargeWebp)) {
$fileWatermarkLarge = $fileWatermarkLargeWebp;
} else if (File::exists($fileWatermarkLargePng)) {
$fileWatermarkLarge = $fileWatermarkLargePng;
} else if (File::exists($fileWatermarkLargeAvif)) {
$fileWatermarkLarge = $fileWatermarkLargeAvif;
}
if (File::exists($fileWatermarkLargeWebpRoot)) {
$fileWatermarkLargeRoot = $fileWatermarkLargeWebpRoot;
} else if (File::exists($fileWatermarkLargePngRoot)) {
$fileWatermarkLargeRoot = $fileWatermarkLargePngRoot;
} else if (File::exists($fileWatermarkLargeAvifRoot)) {
$fileWatermarkLargeRoot = $fileWatermarkLargeAvifRoot;
}
} else if ($type == IMAGETYPE_AVIF){
if (File::exists($fileWatermarkMediumAvif)) {
$fileWatermarkMedium = $fileWatermarkMediumAvif;
} else if (File::exists($fileWatermarkMediumPng)) {
$fileWatermarkMedium = $fileWatermarkMediumPng;
} else if (File::exists($fileWatermarkMediumWebp)) {
$fileWatermarkMedium = $fileWatermarkMediumWebp;
}
if (File::exists($fileWatermarkMediumAvifRoot)) {
$fileWatermarkMediumRoot = $fileWatermarkMediumAvifRoot;
} else if (File::exists($fileWatermarkMediumPngRoot)) {
$fileWatermarkMediumRoot = $fileWatermarkMediumPngRoot;
} else if (File::exists($fileWatermarkMediumWebpRoot)) {
$fileWatermarkMediumRoot = $fileWatermarkMediumWebpRoot;
}
if (File::exists($fileWatermarkLargeAvif)) {
$fileWatermarkLarge = $fileWatermarkLargeAvif;
} else if (File::exists($fileWatermarkLargePng)) {
$fileWatermarkLarge = $fileWatermarkLargePng;
} else if (File::exists($fileWatermarkLargeWebp)) {
$fileWatermarkLarge = $fileWatermarkLargeWebp;
}
if (File::exists($fileWatermarkLargeAvifRoot)) {
$fileWatermarkLargeRoot = $fileWatermarkLargeAvifRoot;
} else if (File::exists($fileWatermarkLargePngRoot)) {
$fileWatermarkLargeRoot = $fileWatermarkLargePngRoot;
} else if (File::exists($fileWatermarkLargeWebpRoot)) {
$fileWatermarkLargeRoot = $fileWatermarkLargeWebpRoot;
}
} else {
if (File::exists($fileWatermarkMediumPng)) {
$fileWatermarkMedium = $fileWatermarkMediumPng;
} else if (File::exists($fileWatermarkMediumWebp)) {
$fileWatermarkMedium = $fileWatermarkMediumWebp;
} else if (File::exists($fileWatermarkMediumAvif)) {
$fileWatermarkMedium = $fileWatermarkMediumAvif;
}
if (File::exists($fileWatermarkMediumPngRoot)) {
$fileWatermarkMediumRoot = $fileWatermarkMediumPngRoot;
} else if (File::exists($fileWatermarkMediumWebpRoot)) {
$fileWatermarkMediumRoot = $fileWatermarkMediumWebpRoot;
} else if (File::exists($fileWatermarkMediumAvifRoot)) {
$fileWatermarkMediumRoot = $fileWatermarkMediumAvifRoot;
}
if (File::exists($fileWatermarkLargePng)) {
$fileWatermarkLarge = $fileWatermarkLargePng;
} else if (File::exists($fileWatermarkLargeWebp)) {
$fileWatermarkLarge = $fileWatermarkLargeWebp;
} else if (File::exists($fileWatermarkLargeAvif)) {
$fileWatermarkLarge = $fileWatermarkLargeAvif;
}
if (File::exists($fileWatermarkLargePngRoot)) {
$fileWatermarkLargeRoot = $fileWatermarkLargePngRoot;
} else if (File::exists($fileWatermarkLargeWebpRoot)) {
$fileWatermarkLargeRoot = $fileWatermarkLargeWebpRoot;
} else if (File::exists($fileWatermarkLargeAvifRoot)) {
$fileWatermarkLargeRoot = $fileWatermarkLargeAvifRoot;
}
}
clearstatcache();
// Which Watermark will be used
if ($thumbnailMedium) {
if ($watermarkParams['create'] == 1 && $fileWatermarkMedium) {
$fileWatermark = $fileWatermarkMedium;
} else if ($watermarkParams['create'] == 2 && $fileWatermarkMediumRoot) {
$fileWatermark = $fileWatermarkMediumRoot;
} else if ($fileWatermarkMedium) {
$fileWatermark = $fileWatermarkMedium;
} else if ($fileWatermarkMediumRoot) {
$fileWatermark = $fileWatermarkMediumRoot;
} else {
$fileWatermark = '';
}
} else if ($thumbnailLarge) {
if ($watermarkParams['create'] == 1 && $fileWatermarkLarge) {
$fileWatermark = $fileWatermarkLarge;
} else if ($watermarkParams['create'] == 2 && $fileWatermarkLargeRoot) {
$fileWatermark = $fileWatermarkLargeRoot;
} else if ($fileWatermarkLarge) {
$fileWatermark = $fileWatermarkLarge;
} else if ($fileWatermarkLargeRoot) {
$fileWatermark = $fileWatermarkLargeRoot;
} else {
$fileWatermark = '';
}
} else {
$fileWatermark = '';
}
if (!File::exists($fileWatermark)) {
$fileWatermark = '';
}
if ($fileWatermark != '') {
list($wW, $hW, $typeW) = GetImageSize($fileWatermark);
switch ($watermarkParams['x']) {
case 'left':
$locationX = 0;
break;
case 'right':
$locationX = $dst[2] - $wW;
break;
case 'center':
Default:
$locationX = ($dst[2] / 2) - ($wW / 2);
break;
}
switch ($watermarkParams['y']) {
case 'top':
$locationY = 0;
break;
case 'bottom':
$locationY = $dst[3] - $hW;
break;
case 'middle':
Default:
$locationY = ($dst[3] / 2) - ($hW / 2);
break;
}
}
} else {
$fileWatermark = '';
}
}
/*if ($memory < 50) {
ini_set('memory_limit', '50M');
$memoryLimitChanged = 1;
}*/
// Resampling
// in file
// Watemark
if ($fileWatermark != '') {
$ext = File::getExt($fileWatermark);
if ($ext == 'webp') {
if (!function_exists('ImageCreateFromWEBP')) {
$errorMsg = 'ErrorNoWEBPFunction';
return false;
}
$waterImage1=ImageCreateFromWEBP($fileWatermark);
//imagealphablending($waterImage1, false);
//imagesavealpha($waterImage1, true);
} else if ($ext == 'avif') {
if (!function_exists('ImageCreateFromAVIF')) {
$errorMsg = 'ErrorNoAVIFFunction';
return false;
}
$waterImage1=ImageCreateFromAVIF($fileWatermark);
//imagealphablending($waterImage1, false);
//imagesavealpha($waterImage1, true);
} else {
if (!function_exists('ImageCreateFromPNG')) {
$errorMsg = 'ErrorNoPNGFunction';
return false;
}
$waterImage1=ImageCreateFromPNG($fileWatermark);
//imagealphablending($waterImage1, false);
//imagesavealpha($waterImage1, true);
}
}
// End Watermark - - - - - - - - - - - - - - - - - -
switch($type) {
case IMAGETYPE_JPEG:
if (!function_exists('ImageCreateFromJPEG')) {
$errorMsg = 'ErrorNoJPGFunction';
return false;
}
//$image1 = ImageCreateFromJPEG($fileIn);
try {
$image1 = ImageCreateFromJPEG($fileIn);
} catch(\Exception $exception) {
$errorMsg = 'ErrorJPGFunction';
return false;
}
break;
case IMAGETYPE_PNG :
if (!function_exists('ImageCreateFromPNG')) {
$errorMsg = 'ErrorNoPNGFunction';
return false;
}
//$image1 = ImageCreateFromPNG($fileIn);
try {
$image1 = ImageCreateFromPNG($fileIn);
} catch(\Exception $exception) {
$errorMsg = 'ErrorPNGFunction';
return false;
}
break;
case IMAGETYPE_GIF :
if (!function_exists('ImageCreateFromGIF')) {
$errorMsg = 'ErrorNoGIFFunction';
return false;
}
//$image1 = ImageCreateFromGIF($fileIn);
try {
$image1 = ImageCreateFromGIF($fileIn);
} catch(\Exception $exception) {
$errorMsg = 'ErrorGIFFunction';
return false;
}
break;
case IMAGETYPE_WEBP:
if (!function_exists('ImageCreateFromWEBP')) {
$errorMsg = 'ErrorNoWEBPFunction';
return false;
}
//$image1 = ImageCreateFromGIF($fileIn);
try {
$image1 = ImageCreateFromWEBP($fileIn);
} catch(\Exception $exception) {
$errorMsg = 'ErrorWEBPFunction';
return false;
}
break;
case IMAGETYPE_AVIF:
if (!function_exists('imagecreatefromavif')) {
$errorMsg = 'ErrorNoAVIFFunction';
return false;
}
//$image1 = ImageCreateFromGIF($fileIn);
try {
$image1 = imagecreatefromavif($fileIn);
} catch(\Exception $exception) {
$errorMsg = 'ErrorAVIFFunction';
return false;
}
break;
case IMAGETYPE_WBMP:
if (!function_exists('ImageCreateFromWBMP')) {
$errorMsg = 'ErrorNoWBMPFunction';
return false;
}
//$image1 = ImageCreateFromWBMP($fileIn);
try {
$image1 = ImageCreateFromWBMP($fileIn);
} catch(\Exception $exception) {
$errorMsg = 'ErrorWBMPFunction';
return false;
}
break;
Default:
$errorMsg = 'ErrorNotSupportedImage';
return false;
break;
}
if ($image1) {
$image2 = @ImageCreateTruecolor($dst[2], $dst[3]);
if (!$image2) {
$errorMsg = 'ErrorNoImageCreateTruecolor';
return false;
}
switch($type) {
case IMAGETYPE_PNG:
case IMAGETYPE_WEBP:
case IMAGETYPE_AVIF:
//imagealphablending($image1, false);
@imagealphablending($image2, false);
//imagesavealpha($image1, true);
@imagesavealpha($image2, true);
break;
}
if ($exif_rotate == 1) {
// Examine the EXIF Orientation flag (read earlier) to determine if the image needs to be rotated prior to the ImageCopyResampled call
// Use the imagerotate() function to perform the rotation, if required
if(isset($exif['Orientation']) && !empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$image1 = imagerotate($image1,90,0);
// @imagealphablending($image1, false);
// @imagesavealpha($image1, true);
break;
case 3:
$image1 = imagerotate($image1,180,0);
// @imagealphablending($image1, false);
// @imagesavealpha($image1, true);
break;
case 6:
$image1 = imagerotate($image1,-90,0);
// @imagealphablending($image1, false);
// @imagesavealpha($image1, true);
break;
}
}
}
ImageCopyResampled($image2, $image1, $dst[0],$dst[1], $src[0],$src[1], $dst[2],$dst[3], $src[2],$src[3]);
// Watermark - - - - - -
if ($fileWatermark != '') {
//imagecolortransparent($waterImage1, imagecolorallocate($waterImage1, 0, 0, 0));
//imagepalettetotruecolor($waterImage1);
//imagealphablending($waterImage1, true);
//imagesavealpha($waterImage1, true);
//imagecolortransparent($image2, imagecolorallocate($image2, 0, 0, 0));
//imagepalettetotruecolor($image2);
imagealphablending($image2, true);// Needed for webp and avif transparency
//imagesavealpha($image2, true);
ImageCopy($image2, $waterImage1, (int)$locationX, (int)$locationY, 0, 0, (int)$wW, (int)$hW);
}
// End Watermark - - - -
// Display the Image - not used
if ($fileOut == null) {
header("Content-type: ". image_type_to_mime_type($typeOut));
}
// Create the file
if ($typeOut == null) { // no bitmap
$typeOut = ($type == IMAGETYPE_WBMP) ? IMAGETYPE_PNG : $type;
}
switch($typeOut) {
case IMAGETYPE_JPEG:
if (!function_exists('ImageJPEG')) {
$errorMsg = 'ErrorNoJPGFunction';
return false;
}
if ($jfile_thumbs == 1) {
ob_start();
if (!@ImageJPEG($image2, NULL, $jpeg_quality)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgJPEGToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgJPEGToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@ImageJPEG($image2, $fileOut, $jpeg_quality)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
case IMAGETYPE_PNG :
if (!function_exists('ImagePNG')) {
$errorMsg = 'ErrorNoPNGFunction';
return false;
}
if ($jfile_thumbs == 1) {
ob_start();
if (!@ImagePNG($image2, NULL)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgPNGToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgPNGToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@ImagePNG($image2, $fileOut)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
case IMAGETYPE_GIF :
if (!function_exists('ImageGIF')) {
$errorMsg = 'ErrorNoGIFFunction';
return false;
}
if ($jfile_thumbs == 1) {
ob_start();
if (!@ImageGIF($image2, NULL)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgGIFToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgGIFToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@ImageGIF($image2, $fileOut)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
case IMAGETYPE_WEBP :
if (!function_exists('ImageWEBP')) {
$errorMsg = 'ErrorNoWEBPFunction';
return false;
}
if ($jfile_thumbs == 1) {
ob_start();
if (!@imagewebp($image2, NULL, $webp_quality)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgWEBPToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgWEBPToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@imagewebp($image2, $fileOut, $webp_quality)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
case IMAGETYPE_AVIF :
if (!function_exists('ImageAVIF')) {
$errorMsg = 'ErrorNoAVIFFunction';
return false;
}
if ($jfile_thumbs == 1) {
ob_start();
if (!@imageavif($image2, NULL, $avif_quality)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgAVIFToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgAVIFToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@imageavif($image2, $fileOut, $avif_quality)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
default:
$errorMsg = 'ErrorNotSupportedImage';
return false;
break;
}
// free memory
ImageDestroy($image1);
ImageDestroy($image2);
if (isset($waterImage1)) {
ImageDestroy($waterImage1);
}
/*if ($memoryLimitChanged == 1) {
$memoryString = $memory . 'M';
ini_set('memory_limit', $memoryString);
}*/
$errorMsg = ''; // Success
return true;
} else {
$errorMsg = 'Error1';
return false;
}
/*if ($memoryLimitChanged == 1) {
$memoryString = $memory . 'M';
ini_set('memory_limit', $memoryString);
}*/
}
$errorMsg = 'Error2';
return false;
}
}
?>

View File

@ -0,0 +1,519 @@
<?php
/**
* @package Phoca Gallery
* @author Jan Pavelka - https://www.phoca.cz
* @copyright Copyright (C) Jan Pavelka https://www.phoca.cz
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 and later
* @cms Joomla
* @copyright Copyright (C) Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
use Joomla\CMS\Factory;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Language\Text;
jimport( 'joomla.filesystem.folder' );
jimport( 'joomla.filesystem.file' );
phocagalleryimport('phocagallery.render.renderprocess');
phocagalleryimport('phocagallery.file.file');
phocagalleryimport('phocagallery.image.image');
register_shutdown_function(function(){
$error = error_get_last();
if(null !== $error) {
if (isset($error['type']) && $error['type'] == 1) {
$app = Factory::getApplication();
$app->redirect('index.php?option=com_phocagallery&view=phocagalleryfe&error=1');
exit;
}
}
});
class PhocaGalleryImageRotate
{
public static function rotateImage($thumbName, $size, $angle=90, &$errorMsg) {
$params = ComponentHelper::getParams('com_phocagallery') ;
$jfile_thumbs = $params->get( 'jfile_thumbs', 1 );
$webp_quality = $params->get( 'webp_quality', 80 );
$webp_quality = PhocaGalleryImage::getJpegQuality($webp_quality);
$avif_quality = $params->get( 'avif_quality', 80 );
$avif_quality = PhocaGalleryImage::getJpegQuality($avif_quality);
$jpeg_quality = $params->get( 'jpeg_quality', 85 );
$jpeg_quality = PhocaGalleryImage::getJpegQuality($jpeg_quality);
// Try to change the size
/*$memory = 8;
$memoryLimitChanged = 0;
$memory = (int)ini_get( 'memory_limit' );
if ($memory == 0) {
$memory = 8;
}*/
$fileIn = $thumbName->abs;
$fileOut = $thumbName->abs;
if ($fileIn !== '' && file_exists($fileIn)) {
//array of width, height, IMAGETYPE, "height=x width=x" (string)
list($w, $h, $type) = GetImageSize($fileIn);
// we got the info from GetImageSize
if ($w > 0 && $h > 0 && $type !='') {
// Change the $w against $h because of rotating
$src = array(0,0, $w, $h);
$dst = array(0,0, $h, $w);
} else {
$errorMsg = 'ErrorWorHorType';
return false;
}
// Try to increase memory
/*if ($memory < 50) {
ini_set('memory_limit', '50M');
$memoryLimitChanged = 1;
}*/
switch($type)
{
case IMAGETYPE_JPEG:
if (!function_exists('ImageCreateFromJPEG')) {
$errorMsg = 'ErrorNoJPGFunction';
return false;
}
//$image1 = ImageCreateFromJPEG($fileIn);
try {
$image1 = ImageCreateFromJPEG($fileIn);
} catch(\Exception $exception) {
$errorMsg = 'ErrorJPGFunction';
return false;
}
break;
case IMAGETYPE_PNG :
if (!function_exists('ImageCreateFromPNG')) {
$errorMsg = 'ErrorNoPNGFunction';
return false;
}
//$image1 = ImageCreateFromPNG($fileIn);
try {
$image1 = ImageCreateFromPNG($fileIn);
} catch(\Exception $exception) {
$errorMsg = 'ErrorPNGFunction';
return false;
}
break;
case IMAGETYPE_GIF :
if (!function_exists('ImageCreateFromGIF')) {
$errorMsg = 'ErrorNoGIFFunction';
return false;
}
//$image1 = ImageCreateFromGIF($fileIn);
try {
$image1 = ImageCreateFromGIF($fileIn);
} catch(\Exception $exception) {
$errorMsg = 'ErrorGIFFunction';
return false;
}
break;
case IMAGETYPE_WEBP :
if (!function_exists('ImageCreateFromWEBP')) {
$errorMsg = 'ErrorNoWEBPFunction';
return false;
}
//$image1 = ImageCreateFromGIF($fileIn);
try {
$image1 = ImageCreateFromWEBP($fileIn);
} catch(\Exception $exception) {
$errorMsg = 'ErrorWEBPFunction';
return false;
}
break;
case IMAGETYPE_AVIF :
if (!function_exists('imagecreatefromavif')) {
$errorMsg = 'ErrorNoAVIFFunction';
return false;
}
//$image1 = ImageCreateFromGIF($fileIn);
try {
$image1 = imagecreatefromavif($fileIn);
} catch(\Exception $exception) {
$errorMsg = 'ErrorAVIFFunction';
return false;
}
break;
case IMAGETYPE_WBMP:
if (!function_exists('ImageCreateFromWBMP')) {
$errorMsg = 'ErrorNoWBMPFunction';
return false;
}
//$image1 = ImageCreateFromWBMP($fileIn);
try {
$image1 = ImageCreateFromWBMP($fileIn);
} catch(\Exception $exception) {
$errorMsg = 'ErrorWBMPFunction';
return false;
}
break;
Default:
$errorMsg = 'ErrorNotSupportedImage';
return false;
break;
}
if ($image1) {
// Building image for ROTATING
/* $image2 = @ImageCreateTruecolor($dst[2], $dst[3]);
if (!$image2) {
return 'ErrorNoImageCreateTruecolor';
}*/
/* if(!function_exists("imagerotate")) {
$errorMsg = 'ErrorNoImageRotate';
return false;
}*/
switch($type)
{
case IMAGETYPE_PNG:
case IMAGETYPE_WEBP:
case IMAGETYPE_AVIF:
// imagealphablending($image1, false);
// imagesavealpha($image1, true);
if(!function_exists("imagecolorallocate")) {
$errorMsg = 'ErrorNoImageColorAllocate';
return false;
}
if(!function_exists("imagefill")) {
$errorMsg = 'ErrorNoImageFill';
return false;
}
if(!function_exists("imagecolortransparent")) {
$errorMsg = 'ErrorNoImageColorTransparent';
return false;
}
$colBlack = imagecolorallocate($image1, 0, 0, 0);
if(!function_exists("imagerotate")) {
$image2 = PhocaGalleryImageRotate::imageRotate($image1, $angle, $colBlack);
} else {
$image2 = imagerotate($image1, $angle, $colBlack);
}
//imagefill($image2, 0, 0, $colBlack);
//imagecolortransparent($image2, $colBlack);
imagealphablending($image2, false);
imagesavealpha($image2, true);
break;
Default:
if(!function_exists("imagerotate")) {
$image2 = PhocaGalleryImageRotate::imageRotate($image1, $angle, 0);
} else {
$image2 = imageRotate($image1, $angle, 0);
}
break;
}
// Get the image size and resize the rotated image if necessary
$rotateWidth = imagesx($image2);// Get the size from rotated image
$rotateHeight = imagesy($image2);// Get the size from rotated image
$parameterSize = PhocaGalleryFileThumbnail::getThumbnailResize($size);
$newWidth = $parameterSize['width']; // Get maximum sizes, they can be displayed
$newHeight = $parameterSize['height'];// Get maximum sizes, they can be displayed
$scale = (($newWidth / $rotateWidth) < ($newHeight / $rotateHeight)) ? ($newWidth / $rotateWidth) : ($newHeight / $rotateHeight); // smaller rate
$src = array(0,0, $rotateWidth, $rotateHeight);
$dst = array(0,0, floor($rotateWidth*$scale), floor($rotateHeight*$scale));
// If original is smaller than thumbnail size, don't resize it
if ($src[2] > $dst[2] || $src[3] > $dst[3]) {
// Building image for RESIZING THE ROTATED IMAGE
$image3 = @ImageCreateTruecolor($dst[2], $dst[3]);
if (!$image3) {
$errorMsg = 'ErrorNoImageCreateTruecolor';
return false;
}
ImageCopyResampled($image3, $image2, $dst[0],$dst[1], $src[0],$src[1], $dst[2],$dst[3], $src[2],$src[3]);
switch($type)
{
case IMAGETYPE_PNG:
case IMAGETYPE_WEBP:
case IMAGETYPE_AVIF:
// imagealphablending($image2, true);
// imagesavealpha($image2, true);
if(!function_exists("imagecolorallocate")) {
$errorMsg = 'ErrorNoImageColorAllocate';
return false;
}
if(!function_exists("imagefill")) {
$errorMsg = 'ErrorNoImageFill';
return false;
}
if(!function_exists("imagecolortransparent")) {
$errorMsg = 'ErrorNoImageColorTransparent';
return false;
}
$colBlack = imagecolorallocate($image3, 0, 0, 0);
imagefill($image3, 0, 0, $colBlack);
imagecolortransparent($image3, $colBlack);
break;
}
} else {
$image3 = $image2;
}
switch($type) {
case IMAGETYPE_JPEG:
if (!function_exists('ImageJPEG')) {
$errorMsg = 'ErrorNoJPGFunction';
return false;
}
if ($jfile_thumbs == 1) {
ob_start();
if (!@ImageJPEG($image3, NULL, $jpeg_quality)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgJPEGToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgJPEGToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@ImageJPEG($image3, $fileOut, $jpeg_quality)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
case IMAGETYPE_PNG :
if (!function_exists('ImagePNG')) {
$errorMsg = 'ErrorNoPNGFunction';
return false;
}
if ($jfile_thumbs == 1) {
ob_start();
if (!@ImagePNG($image3, NULL)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgPNGToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgPNGToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@ImagePNG($image3, $fileOut)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
case IMAGETYPE_GIF :
if (!function_exists('ImageGIF')) {
$errorMsg = 'ErrorNoGIFFunction';
return false;
}
if ($jfile_thumbs == 1) {
ob_start();
if (!@ImageGIF($image3, NULL)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgGIFToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgGIFToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@ImageGIF($image3, $fileOut)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
case IMAGETYPE_WEBP :
if (!function_exists('ImageWEBP')) {
$errorMsg = 'ErrorNoWEBPFunction';
return false;
}
if ($jfile_thumbs == 1) {
ob_start();
if (!@imagewebp($image3, NULL, $webp_quality)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgWEBPToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgWEBPToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@imagewebp($image3, $fileOut, $webp_quality)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
case IMAGETYPE_AVIF :
if (!function_exists('ImageAVIF')) {
$errorMsg = 'ErrorNoAVIFFunction';
return false;
}
if ($jfile_thumbs == 1) {
ob_start();
if (!@imageavif($image3, NULL, $avif_quality)) {
ob_end_clean();
$errorMsg = 'ErrorWriteFile';
return false;
}
$imgAVIFToWrite = ob_get_contents();
ob_end_clean();
if(!File::write( $fileOut, $imgAVIFToWrite)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
} else {
if (!@imageavif($image3, $fileOut, $avif_quality)) {
$errorMsg = 'ErrorWriteFile';
return false;
}
}
break;
Default:
$errorMsg = 'ErrorNotSupportedImage';
return false;
break;
}
// free memory
if (isset($image1)) {ImageDestroy($image1);}// Original
if (isset($image2)) {ImageDestroy($image2);}// Original
if (isset($image3)) {@ImageDestroy($image3);}// Resized
/*if ($memoryLimitChanged == 1) {
$memoryString = $memory . 'M';
ini_set('memory_limit', $memoryString);
}*/
return true; // Success
} else {
$errorMsg = PhocaGalleryUtils::setMessage($errorMsg, Text::_('COM_PHOCAGALLERY_ERROR_IMAGE_NOT_PROCESS'));
return false;
}
/*if ($memoryLimitChanged == 1) {
$memoryString = $memory . 'M';
ini_set('memory_limit', $memoryString);
}*/
}
$errorMsg = Text::_('COM_PHOCAGALLERY_FILEORIGINAL_NOT_EXISTS');
return false;
}
/* This function is provided by php manual (function.imagerotate.php)
It's a workaround to enables image rotation on distributions which do not
use the bundled gd library (e.g. Debian, Ubuntu).
*/
public static function imageRotate($src_img, $angle, $colBlack = 0) {
if (!imageistruecolor($src_img))
{
$w = imagesx($src_img);
$h = imagesy($src_img);
$t_im = imagecreatetruecolor($w,$h);
imagecopy($t_im,$src_img,0,0,0,0,$w,$h);
$src_img = $t_im;
}
$src_x = imagesx($src_img);
$src_y = imagesy($src_img);
if ($angle == 180)
{
$dest_x = $src_x;
$dest_y = $src_y;
}
elseif ($src_x <= $src_y)
{
$dest_x = $src_y;
$dest_y = $src_x;
}
elseif ($src_x >= $src_y)
{
$dest_x = $src_y;
$dest_y = $src_x;
}
$rotate=imagecreatetruecolor($dest_x,$dest_y);
imagealphablending($rotate, false);
switch ($angle)
{
case 270:
for ($y = 0; $y < ($src_y); $y++)
{
for ($x = 0; $x < ($src_x); $x++)
{
$color = imagecolorat($src_img, $x, $y);
imagesetpixel($rotate, $dest_x - $y - 1, $x, $color);
}
}
break;
case 90:
for ($y = 0; $y < ($src_y); $y++)
{
for ($x = 0; $x < ($src_x); $x++)
{
$color = imagecolorat($src_img, $x, $y);
imagesetpixel($rotate, $y, $dest_y - $x - 1, $color);
}
}
break;
case 180:
for ($y = 0; $y < ($src_y); $y++)
{
for ($x = 0; $x < ($src_x); $x++)
{
$color = imagecolorat($src_img, $x, $y);
imagesetpixel($rotate, $dest_x - $x - 1, $dest_y - $y - 1,
$color);
}
}
break;
Default: $rotate = $src_img;
};
return $rotate;
}
}
?>

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>