Esempio n. 1
0
 function getOrCreateThumbnail($fileNo, $refreshUrl, $small = 0, $medium = 0, $large = 0, $frontUpload = 0)
 {
     if ($frontUpload) {
         $returnFrontMessage = '';
     }
     $onlyThumbnailInfo = 0;
     if ($small == 0 && $medium == 0 && $large == 0) {
         $onlyThumbnailInfo = 1;
     }
     $paramsC = JComponentHelper::getParams('com_phocagallery');
     $additional_thumbnails = $paramsC->get('additional_thumbnails', 0);
     $path = PhocaGalleryPath::getPath();
     $origPathServer = str_replace(DS, '/', $path->image_abs);
     $file['name'] = PhocaGalleryFile::getTitleFromFile($fileNo, 1);
     $file['name_no'] = ltrim($fileNo, '/');
     $file['name_original_abs'] = PhocaGalleryFile::getFileOriginal($fileNo);
     $file['name_original_rel'] = PhocaGalleryFile::getFileOriginal($fileNo, 1);
     $file['path_without_file_name_original'] = str_replace($file['name'], '', $file['name_original_abs']);
     $file['path_without_file_name_thumb'] = str_replace($file['name'], '', $file['name_original_abs'] . 'thumbs' . DS);
     //$file['path_without_name']				= str_replace(DS, '/', JPath::clean($origPathServer));
     //$file['path_with_name_relative_no']		= str_replace($origPathServer, '', $file['name_original']);
     /*
     		$file['path_with_name_relative']		= $path['orig_rel_ds'] . str_replace($origPathServer, '', $file['name_original']);
     		$file['path_with_name_relative_no']		= str_replace($origPathServer, '', $file['name_original']);
     		
     		$file['path_without_name']				= str_replace(DS, '/', JPath::clean($origPath.DS));
     		$file['path_without_name_relative']		= $path['orig_rel_ds'] . str_replace($origPathServer, '', $file['path_without_name']);
     		$file['path_without_name_relative_no']	= str_replace($origPathServer, '', $file['path_without_name']);
     		$file['path_without_name_thumbs'] 		= $file['path_without_name'] .'thumbs';
     		$file['path_without_file_name_original'] 			= str_replace($file['name'], '', $file['name_original']);
     		$file['path_without_name_thumbs_no'] 	= str_replace($file['name'], '', $file['name_original'] .'thumbs');*/
     $ext = strtolower(JFile::getExt($file['name']));
     switch ($ext) {
         case 'jpg':
         case 'png':
         case 'gif':
         case 'jpeg':
             //Get File thumbnails name
             $thumbNameS = PhocaGalleryFileThumbnail::getThumbnailName($fileNo, 'small');
             $file['thumb_name_s_no_abs'] = $thumbNameS->abs;
             $file['thumb_name_s_no_rel'] = $thumbNameS->rel;
             $thumbNameM = PhocaGalleryFileThumbnail::getThumbnailName($fileNo, 'medium');
             $file['thumb_name_m_no_abs'] = $thumbNameM->abs;
             $file['thumb_name_m_no_rel'] = $thumbNameM->rel;
             $thumbNameL = PhocaGalleryFileThumbnail::getThumbnailName($fileNo, 'large');
             $file['thumb_name_l_no_abs'] = $thumbNameL->abs;
             $file['thumb_name_l_no_rel'] = $thumbNameL->rel;
             // Don't create thumbnails from watermarks...
             $dontCreateThumb = PhocaGalleryFileThumbnail::dontCreateThumb($file['name']);
             if ($dontCreateThumb == 1) {
                 $onlyThumbnailInfo = 1;
                 // WE USE $onlyThumbnailInfo FOR NOT CREATE A THUMBNAIL CLAUSE
             }
             // We want only information from the pictures OR
             if ($onlyThumbnailInfo == 0) {
                 $thumbInfo = $fileNo;
                 //Create thumbnail folder if not exists
                 $errorMsg = 'ErrorCreatingFolder';
                 $creatingFolder = PhocaGalleryFileThumbnail::createThumbnailFolder($file['path_without_file_name_original'], $file['path_without_file_name_thumb'], $errorMsg);
                 switch ($errorMsg) {
                     case 'Success':
                         //case 'ThumbnailExists':
                     //case 'ThumbnailExists':
                     case 'DisabledThumbCreation':
                         //case 'OnlyInformation':
                         break;
                     default:
                         // BACKEND OR FRONTEND
                         if ($frontUpload != 1) {
                             PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl, $errorMsg, $frontUpload);
                             exit;
                         } else {
                             $returnFrontMessage = $errorMsg;
                         }
                         break;
                 }
                 // Folder must exist
                 if (JFolder::exists($file['path_without_file_name_thumb'])) {
                     $errorMsgS = $errorMsgM = $errorMsgL = '';
                     //Small thumbnail
                     if ($small == 1) {
                         PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], $thumbNameS->abs, 'small', $frontUpload, $errorMsgS);
                         if ($additional_thumbnails == 2 || $additional_thumbnails == 3) {
                             PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], str_replace('phoca_thumb_s_', 'phoca_thumb_s1_', $thumbNameS->abs), 'small1', $frontUpload, $errorMsgS);
                             PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], str_replace('phoca_thumb_s_', 'phoca_thumb_s2_', $thumbNameS->abs), 'small2', $frontUpload, $errorMsgS);
                             PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], str_replace('phoca_thumb_s_', 'phoca_thumb_s3_', $thumbNameS->abs), 'small3', $frontUpload, $errorMsgS);
                         }
                     } else {
                         $errorMsgS = 'ThumbnailExists';
                         // in case we only need medium or large, because of if clause bellow
                     }
                     //Medium thumbnail
                     if ($medium == 1) {
                         PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], $thumbNameM->abs, 'medium', $frontUpload, $errorMsgM);
                         if ($additional_thumbnails == 1 || $additional_thumbnails == 3) {
                             PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], str_replace('phoca_thumb_m_', 'phoca_thumb_m1_', $thumbNameM->abs), 'medium1', $frontUpload, $errorMsgM);
                             PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], str_replace('phoca_thumb_m_', 'phoca_thumb_m2_', $thumbNameM->abs), 'medium2', $frontUpload, $errorMsgM);
                             PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], str_replace('phoca_thumb_m_', 'phoca_thumb_m3_', $thumbNameM->abs), 'medium3', $frontUpload, $errorMsgM);
                         }
                     } else {
                         $errorMsgM = 'ThumbnailExists';
                         // in case we only need small or large, because of if clause bellow
                     }
                     //Large thumbnail
                     if ($large == 1) {
                         PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], $thumbNameL->abs, 'large', $frontUpload, $errorMsgL);
                     } else {
                         $errorMsgL = 'ThumbnailExists';
                         // in case we only need small or medium, because of if clause bellow
                     }
                     // Error messages for all 3 thumbnails (if the message contains error string, we got error
                     // Other strings can be:
                     // - ThumbnailExists  - do not display error message nor success page
                     // - OnlyInformation - do not display error message nor success page
                     // - DisabledThumbCreation - do not display error message nor success page
                     $creatingSError = $creatingMError = $creatingLError = false;
                     $creatingSError = preg_match("/Error/i", $errorMsgS);
                     $creatingMError = preg_match("/Error/i", $errorMsgM);
                     $creatingLError = preg_match("/Error/i", $errorMsgL);
                     // BACKEND OR FRONTEND
                     if ($frontUpload != 1) {
                         // There is an error while creating thumbnail in m or in s or in l
                         if ($creatingSError || $creatingMError || $creatingLError) {
                             // if all or two errors appear, we only display the last error message
                             // because the errors in this case is the same
                             if ($errorMsgS != '') {
                                 $creatingError = $errorMsgS;
                             }
                             if ($errorMsgM != '') {
                                 $creatingError = $errorMsgM;
                             }
                             if ($errorMsgL != '') {
                                 $creatingError = $errorMsgL;
                             }
                             PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl, $creatingError);
                             exit;
                         } else {
                             if ($errorMsgS == '' && $errorMsgM == '' && $errorMsgL == '') {
                                 PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                 exit;
                             } else {
                                 if ($errorMsgS == '' && $errorMsgM == '' && $errorMsgL == 'ThumbnailExists') {
                                     PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                     exit;
                                 } else {
                                     if ($errorMsgS == '' && $errorMsgM == 'ThumbnailExists' && $errorMsgL == 'ThumbnailExists') {
                                         PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                         exit;
                                     } else {
                                         if ($errorMsgS == '' && $errorMsgM == 'ThumbnailExists' && $errorMsgL == '') {
                                             PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                             exit;
                                         } else {
                                             if ($errorMsgS == 'ThumbnailExists' && $errorMsgM == 'ThumbnailExists' && $errorMsgL == '') {
                                                 PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                                 exit;
                                             } else {
                                                 if ($errorMsgS == 'ThumbnailExists' && $errorMsgM == '' && $errorMsgL == '') {
                                                     PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                                     exit;
                                                 } else {
                                                     if ($errorMsgS == 'ThumbnailExists' && $errorMsgM == '' && $errorMsgL == 'ThumbnailExists') {
                                                         PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                                         exit;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         // There is an error while creating thumbnail in m or in s or in l
                         if ($creatingSError || $creatingMError || $creatingLError) {
                             // if all or two errors appear, we only display the last error message
                             // because the errors in this case is the same
                             if ($errorMsgS != '') {
                                 $creatingError = $errorMsgS;
                             }
                             if ($errorMsgM != '') {
                                 $creatingError = $errorMsgM;
                             }
                             if ($errorMsgL != '') {
                                 $creatingError = $errorMsgL;
                             }
                             // because the errors in this case is the same
                             $returnFrontMessage = $creatingError;
                         } else {
                             if ($errorMsgS == '' && $errorMsgM == '' && $errorMsgL == '') {
                                 $returnFrontMessage = 'Success';
                             } else {
                                 if ($errorMsgS == '' && $errorMsgM == '' && $errorMsgL == 'ThumbnailExists') {
                                     $returnFrontMessage = 'Success';
                                 } else {
                                     if ($errorMsgS == '' && $errorMsgM == 'ThumbnailExists' && $errorMsgL == 'ThumbnailExists') {
                                         $returnFrontMessage = 'Success';
                                     } else {
                                         if ($errorMsgS == '' && $errorMsgM == 'ThumbnailExists' && $errorMsgL == '') {
                                             $returnFrontMessage = 'Success';
                                         } else {
                                             if ($errorMsgS == 'ThumbnailExists' && $errorMsgM == 'ThumbnailExists' && $errorMsgL == '') {
                                                 $returnFrontMessage = 'Success';
                                             } else {
                                                 if ($errorMsgS == 'ThumbnailExists' && $errorMsgM == '' && $errorMsgL == '') {
                                                     $returnFrontMessage = 'Success';
                                                 } else {
                                                     if ($errorMsgS == 'ThumbnailExists' && $errorMsgM == '' && $errorMsgL == 'ThumbnailExists') {
                                                         $returnFrontMessage = 'Success';
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if ($frontUpload == 1) {
                         return $returnFrontMessage;
                     }
                 }
             }
             break;
     }
     return $file;
 }
Esempio n. 2
0
 /**
  * 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 = JComponentHelper::getParams('com_phocagallery');
     $jfile_thumbs = $params->get('jfile_thumbs', 1);
     $jpeg_quality = $params->get('jpeg_quality', 85);
     $jpeg_quality = PhocaGalleryImage::getJpegQuality($jpeg_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 !== '' && JFile::exists($fileIn)) {
         // array of width, height, IMAGETYPE, "height=x width=x" (string)
         list($w, $h, $type) = GetImageSize($fileIn);
         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
                 $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 = str_replace($fileName, 'watermark-medium.png', $fileIn);
                 $fileWatermarkLarge = str_replace($fileName, 'watermark-large.png', $fileIn);
                 clearstatcache();
                 // Which Watermark will be used
                 if ($thumbnailMedium) {
                     if (JFile::exists($fileWatermarkMedium)) {
                         $fileWatermark = $fileWatermarkMedium;
                     } else {
                         if ($watermarkParams['create'] == 2) {
                             $fileWatermark = $path->image_abs . 'watermark-medium.png';
                         } else {
                             $fileWatermark = '';
                         }
                     }
                 } else {
                     if ($thumbnailLarge) {
                         if (JFile::exists($fileWatermarkLarge)) {
                             $fileWatermark = $fileWatermarkLarge;
                         } else {
                             if ($watermarkParams['create'] == 2) {
                                 $fileWatermark = $path->image_abs . 'watermark-large.png';
                             } else {
                                 $fileWatermark = '';
                             }
                         }
                     } else {
                         $fileWatermark = '';
                     }
                 }
                 if (!JFile::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 != '') {
             if (!function_exists('ImageCreateFromPNG')) {
                 $errorMsg = 'ErrorNoPNGFunction';
                 return false;
             }
             $waterImage1 = ImageCreateFromPNG($fileWatermark);
         }
         // 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_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:
                     //imagealphablending($image1, false);
                     @imagealphablending($image2, false);
                     //imagesavealpha($image1, true);
                     @imagesavealpha($image2, true);
                     break;
             }
             ImageCopyResampled($image2, $image1, $dst[0], $dst[1], $src[0], $src[1], $dst[2], $dst[3], $src[2], $src[3]);
             // Watermark - - - - - -
             if ($fileWatermark != '') {
                 ImageCopy($image2, $waterImage1, $locationX, $locationY, 0, 0, $wW, $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 (!JFile::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 (!JFile::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 (!JFile::write($fileOut, $imgGIFToWrite)) {
                             $errorMsg = 'ErrorWriteFile';
                             return false;
                         }
                     } else {
                         if (!@ImageGIF($image2, $fileOut)) {
                             $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;
 }