예제 #1
0
 /**
  * Resize image with functions from gd/gd2/imagemagick
  *
  * Cropping function adapted from
  * 'Resize Image with Different Aspect Ratio'
  * Author: Nash
  * Website: http://nashruddin.com/Resize_Image_to_Different_Aspect_Ratio_on_the_fly
  *
  * @param   &string $debugoutput            debug information
  * @param   string  $src_file               Path to source file
  * @param   string  $dest_file              Path to destination file
  * @param   int     $useforresizedirection  Thumbnails only:
  *                                          Resize to width/height ratio or free setting
  * @param   int     $new_width              Width to resize
  * @param   int     $thumbheight            Height to resize
  * @param   int     $method                 1=gd1, 2=gd2, 3=im
  * @param   int     $dest_qual              $config->jg_thumbquality/jg_picturequality
  * @param   boolean $max_width              true=resize to maxwidth
  * @param   int     $cropposition           $config->jg_cropposition
  * @return  boolean True on success, false otherwise
  * @since   1.0.0
  */
 public static function resizeImage(&$debugoutput, $src_file, $dest_file, $useforresizedirection, $new_width, $thumbheight, $method, $dest_qual, $max_width = false, $cropposition)
 {
     $config = JoomConfig::getInstance();
     // Ensure that the pathes are valid and clean
     $src_file = JPath::clean($src_file);
     $dest_file = JPath::clean($dest_file);
     // Doing resize instead of thumbnail, copy original and remove it.
     $imginfo = getimagesize($src_file);
     if (!$imginfo) {
         $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_FILE_NOT_FOUND') . '<br />';
         return false;
     }
     // GD can only handle JPG & PNG images
     if ($imginfo[2] != IMAGETYPE_JPEG && $imginfo[2] != IMAGETYPE_PNG && $imginfo[2] != IMAGETYPE_GIF && ($method == 'gd1' || $method == 'gd2')) {
         $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_GD_ONLY_JPG_PNG') . '<br />';
         return false;
     }
     $imagetype = array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG', 4 => 'SWF', 5 => 'PSD', 6 => 'BMP', 7 => 'TIFF', 8 => 'TIFF', 9 => 'JPC', 10 => 'JP2', 11 => 'JPX', 12 => 'JB2', 13 => 'SWC', 14 => 'IFF');
     $imginfo[2] = $imagetype[$imginfo[2]];
     // Height/width
     $srcWidth = $imginfo[0];
     $srcHeight = $imginfo[1];
     if ($max_width && $srcWidth <= $new_width && $srcHeight <= $new_width || !$max_width && $srcWidth <= $new_width && $srcHeight <= $thumbheight) {
         // If source image is already of the same size or smaller than the image
         // which shall be created only copy the source image to destination
         $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_RESIZE_NOT_NECESSARY') . '<br />';
         if (!JFile::copy($src_file, $dest_file)) {
             $debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_COPYING', $dest_file) . ' ' . JText::_('COM_JOOMGALLERY_COMMON_CHECK_PERMISSIONS') . '<br />';
             return false;
         }
         return true;
     }
     // For free resizing and cropping the center
     $offsetx = null;
     $offsety = null;
     if ($max_width) {
         $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_RESIZE_TO_MAX') . '<br />';
         if ($new_width <= 0) {
             $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_ERROR_NO_VALID_WIDTH_OR_HEIGHT') . '<br />';
             return false;
         }
         $ratio = max($srcHeight, $srcWidth) / $new_width;
     } else {
         // Resizing to thumbnail
         $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_CREATE_THUMBNAIL_FROM') . ' ' . $imginfo[2] . ', ' . $imginfo[0] . ' x ' . $imginfo[1] . '...<br />';
         if ($new_width <= 0 || $thumbheight <= 0) {
             $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_ERROR_NO_VALID_WIDTH_OR_HEIGHT') . '<br />';
             return false;
         }
         switch ($useforresizedirection) {
             // Convert to height ratio
             case 0:
                 $ratio = $srcHeight / $thumbheight;
                 $testwidth = $srcWidth / $ratio;
                 // If new width exceeds setted max. width
                 if ($testwidth > $new_width) {
                     $ratio = $srcWidth / $new_width;
                 }
                 break;
                 // Convert to width ratio
             // Convert to width ratio
             case 1:
                 $ratio = $srcWidth / $new_width;
                 $testheight = $srcHeight / $ratio;
                 // If new height exceeds the setted max. height
                 if ($testheight > $thumbheight) {
                     $ratio = $srcHeight / $thumbheight;
                 }
                 break;
                 // Free resizing and cropping the center
             // Free resizing and cropping the center
             case 2:
                 if ($srcWidth < $new_width) {
                     $new_width = $srcWidth;
                 }
                 if ($srcHeight < $thumbheight) {
                     $thumbheight = $srcHeight;
                 }
                 // Expand the thumbnail's aspect ratio
                 // to fit the width/height of the image
                 $ratiowidth = $srcWidth / $new_width;
                 $ratioheight = $srcHeight / $thumbheight;
                 if ($ratiowidth < $ratioheight) {
                     $ratio = $ratiowidth;
                 } else {
                     $ratio = $ratioheight;
                 }
                 // Calculate the offsets for cropping the source image according
                 // to thumbposition
                 switch ($cropposition) {
                     // Left upper corner
                     case 0:
                         $offsetx = 0;
                         $offsety = 0;
                         break;
                         // Right upper corner
                     // Right upper corner
                     case 1:
                         $offsetx = floor($srcWidth - $new_width * $ratio);
                         $offsety = 0;
                         break;
                         // Left lower corner
                     // Left lower corner
                     case 3:
                         $offsetx = 0;
                         $offsety = floor($srcHeight - $thumbheight * $ratio);
                         break;
                         // Right lower corner
                     // Right lower corner
                     case 4:
                         $offsetx = floor($srcWidth - $new_width * $ratio);
                         $offsety = floor($srcHeight - $thumbheight * $ratio);
                         break;
                         // Default center
                     // Default center
                     default:
                         $offsetx = floor(($srcWidth - $new_width * $ratio) * 0.5);
                         $offsety = floor(($srcHeight - $thumbheight * $ratio) * 0.5);
                         break;
                 }
         }
     }
     if (is_null($offsetx) && is_null($offsety)) {
         $ratio = max($ratio, 1.0);
         $destWidth = (int) ($srcWidth / $ratio);
         $destHeight = (int) ($srcHeight / $ratio);
     } else {
         $destWidth = $new_width;
         $destHeight = $thumbheight;
         $srcWidth = (int) ($destWidth * $ratio);
         $srcHeight = (int) ($destHeight * $ratio);
     }
     // Method for creation of the resized image
     switch ($method) {
         case 'gd1':
             if (!function_exists('imagecreatefromjpeg')) {
                 $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_GD_LIBARY_NOT_INSTALLED');
                 return false;
             }
             if ($imginfo[2] == 'JPG') {
                 $src_img = imagecreatefromjpeg($src_file);
             } else {
                 if ($imginfo[2] == 'PNG') {
                     $src_img = imagecreatefrompng($src_file);
                 } else {
                     $src_img = imagecreatefromgif($src_file);
                 }
             }
             if (!$src_img) {
                 return false;
             }
             $dst_img = imagecreate($destWidth, $destHeight);
             if (!is_null($offsetx) && !is_null($offsety)) {
                 imagecopyresized($dst_img, $src_img, 0, 0, $offsetx, $offsety, $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
             } else {
                 imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
             }
             if (!@imagejpeg($dst_img, $dest_file, $dest_qual)) {
                 // Workaround for servers with wwwrun problem
                 $dir = dirname($dest_file);
                 JoomFile::chmod($dir, '0777', true);
                 imagejpeg($dst_img, $dest_file, $dest_qual);
                 JoomFile::chmod($dir, '0755', true);
             }
             imagedestroy($src_img);
             imagedestroy($dst_img);
             break;
         case 'gd2':
             if (!function_exists('imagecreatefromjpeg')) {
                 $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_GD_LIBARY_NOT_INSTALLED');
                 return false;
             }
             if (!function_exists('imagecreatetruecolor')) {
                 $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_GD_NO_TRUECOLOR');
                 return false;
             }
             if ($imginfo[2] == 'JPG') {
                 $src_img = imagecreatefromjpeg($src_file);
             } else {
                 if ($imginfo[2] == 'PNG') {
                     $src_img = imagecreatefrompng($src_file);
                 } else {
                     $src_img = imagecreatefromgif($src_file);
                 }
             }
             if (!$src_img) {
                 return false;
             }
             $dst_img = imagecreatetruecolor($destWidth, $destHeight);
             if ($config->jg_fastgd2thumbcreation == 0) {
                 if (!is_null($offsetx) && !is_null($offsety)) {
                     imagecopyresampled($dst_img, $src_img, 0, 0, $offsetx, $offsety, $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
                 } else {
                     imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
                 }
             } else {
                 if (!is_null($offsetx) && !is_null($offsety)) {
                     JoomFile::fastImageCopyResampled($dst_img, $src_img, 0, 0, $offsetx, $offsety, $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
                 } else {
                     JoomFile::fastImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
                 }
             }
             if (!@imagejpeg($dst_img, $dest_file, $dest_qual)) {
                 // Workaround for servers with wwwrun problem
                 $dir = dirname($dest_file);
                 JoomFile::chmod($dir, '0777', true);
                 imagejpeg($dst_img, $dest_file, $dest_qual);
                 JoomFile::chmod($dir, '0755', true);
             }
             imagedestroy($src_img);
             imagedestroy($dst_img);
             break;
         case 'im':
             $disabled_functions = explode(',', ini_get('disabled_functions'));
             foreach ($disabled_functions as $disabled_function) {
                 if (trim($disabled_function) == 'exec') {
                     $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_EXEC_DISABLED') . '<br />';
                     return false;
                 }
             }
             if (!empty($config->jg_impath)) {
                 $convert_path = $config->jg_impath . 'convert';
             } else {
                 $convert_path = 'convert';
             }
             $commands = '';
             // Crop the source image before resiszing if offsets setted before
             // example of crop: convert input -crop destwidthxdestheight+offsetx+offsety +repage output
             // +repage needed to delete the canvas
             if (!is_null($offsetx) && !is_null($offsety)) {
                 $commands .= ' -crop "' . $srcWidth . 'x' . $srcHeight . '+' . $offsetx . '+' . $offsety . '" +repage';
             }
             // Finally the resize
             $commands .= ' -resize "' . $destWidth . 'x' . $destHeight . '" -quality "' . $dest_qual . '" -unsharp "3.5x1.2+1.0+0.10"';
             $convert = $convert_path . ' ' . $commands . ' "' . $src_file . '" "' . $dest_file . '"';
             $return_var = null;
             $dummy = null;
             @exec($convert, $dummy, $return_var);
             if ($return_var != 0) {
                 // Workaround for servers with wwwrun problem
                 $dir = dirname($dest_file);
                 JoomFile::chmod($dir, '0777', true);
                 @exec($convert, $dummy, $return_var);
                 JoomFile::chmod($dir, '0755', true);
                 if ($return_var != 0) {
                     return false;
                 }
             }
             break;
         default:
             JError::raiseError(500, JText::_('COM_JOOMGALLERY_UPLOAD_UNSUPPORTED_RESIZING_METHOD'));
             break;
     }
     // Set mode of uploaded picture
     JPath::setPermissions($dest_file);
     // We check that the image is valid
     $imginfo = getimagesize($dest_file);
     if (!$imginfo) {
         return false;
     }
     return true;
 }
예제 #2
0
파일: favourites.php 프로젝트: naka211/kkvn
 /**
  * Method to create the zip archive with all selected images
  *
  * @return  boolean True on success, false otherwise
  * @since   1.0.0
  */
 public function createZip()
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.archive');
     $zip_adapter = JArchive::getAdapter('zip');
     // Check whether zip download is allowed
     if (!$this->_config->get('jg_zipdownload') && ($this->_user->get('id') || !$this->_config->get('jg_usefavouritesforpubliczip'))) {
         $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false), JText::_('COM_JOOMGALLERY_FAVOURITES_MSG_NOT_ALLOWED'), 'notice');
     }
     if (is_null($this->piclist)) {
         $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false), $this->output('NO_IMAGES'), 'notice');
     }
     $query = $this->_db->getQuery(true)->select('id')->select('catid')->select('imgfilename')->from(_JOOM_TABLE_IMAGES . ' AS a')->from(_JOOM_TABLE_CATEGORIES . ' AS c')->where('id IN (' . $this->piclist . ')')->where('a.catid      = c.cid')->where('a.published  = 1')->where('a.approved   = 1')->where('c.published  = 1')->where('a.access     IN (' . implode(',', $this->_user->getAuthorisedViewLevels()) . ')')->where('c.access     IN (' . implode(',', $this->_user->getAuthorisedViewLevels()) . ')');
     $this->_db->setQuery($query);
     $rows = $this->_db->loadObjectList();
     if (!count($rows)) {
         $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false), $this->output('NO_IMAGES'), 'notice');
     }
     // Name of the zip archive
     $zipname = 'components/' . _JOOM_OPTION . '/joomgallery_' . date('d_m_Y') . '__';
     if ($userid = $this->_user->get('id')) {
         $zipname .= $userid . '_';
     }
     $zipname .= mt_rand(10000, 99999) . '.zip';
     $files = array();
     if ($this->_config->get('jg_downloadwithwatermark')) {
         $include_watermark = true;
         // Get the 'image' model
         $imageModel = parent::getInstance('image', 'joomgallerymodel');
         // Get the temp path for storing the watermarked image temporarily
         if (!JFolder::exists($this->_ambit->get('temp_path'))) {
             $this->setError(JText::_('COM_JOOMGALLERY_UPLOAD_ERROR_TEMP_MISSING'));
             return false;
         } else {
             $tmppath = $this->_ambit->get('temp_path');
         }
     } else {
         $include_watermark = false;
     }
     $categories = $this->_ambit->getCategoryStructure();
     foreach ($rows as &$row) {
         if (!isset($categories[$row->catid])) {
             continue;
         }
         // Get the original image if existent, otherwise the detail image
         $orig = $this->_ambit->getImg('orig_path', $row->id);
         $img = $this->_ambit->getImg('img_path', $row->id);
         if (file_exists($orig)) {
             $image = $orig;
         } else {
             if (file_exists($img)) {
                 $image = $img;
             } else {
                 $image = null;
                 continue;
             }
         }
         $files[$row->id]['name'] = $row->imgfilename;
         // Watermark the image before if needed
         if ($include_watermark) {
             // Get the image resource of watermarked image
             $imgres = $imageModel->includeWatermark($image);
             // Start output buffering
             ob_start();
             // According to mime type output the watermarked image resource to file
             $info = getimagesize($image);
             switch ($info[2]) {
                 case 1:
                     imagegif($imgres);
                     break;
                 case 2:
                     imagejpeg($imgres);
                     break;
                 case 3:
                     imagepng($imgres);
                     break;
                 default:
                     JError::raiseError(404, JText::sprintf('COM_JOOMGALLERY_COMMON_MSG_MIME_NOT_ALLOWED', $mime));
                     break;
             }
             // Read the content from output buffer and fill the array element
             $files[$row->id]['data'] = ob_get_contents();
             // Delete the output buffer
             ob_end_clean();
         } else {
             $files[$row->id]['data'] = JFile::read($image);
         }
         // Increase download counter for that image
         $this->download($row->id);
     }
     if (!count($files)) {
         $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false), $this->output('NO_IMAGES'), 'notice');
     }
     // Trigger event 'onJoomBeforeZipDownload'
     $plugins = $this->_mainframe->triggerEvent('onJoomBeforeZipDownload', array(&$files));
     if (in_array(false, $plugins, true)) {
         $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false));
     }
     $createzip = $zip_adapter->create($zipname, $files);
     if (!$createzip) {
         // Workaround for servers with wwwwrun problem
         JoomFile::chmod(JPATH_COMPONENT, '0777', true);
         $createzip = $zip_adapter->create($zipname, $files, 'zip');
         JoomFile::chmod(JPATH_COMPONENT, '0755', true);
     }
     if (!$createzip) {
         $this->setError(JText::_('COM_JOOMGALLERY_FAVOURITES_ERROR_CREATEZIP'));
         return false;
     }
     if ($this->_user->get('id')) {
         if ($this->user_exists) {
             $query = $this->_db->getQuery(true)->select('zipname')->from(_JOOM_TABLE_USERS)->where('uuserid = ' . $this->_user->get('id'));
             $this->_db->setQuery($query);
             if ($old_zip = $this->_db->loadResult()) {
                 if (file_exists($old_zip)) {
                     jimport('joomla.filesystem.file');
                     JFile::delete($old_zip);
                 }
             }
             $query = $this->_db->getQuery(true)->update(_JOOM_TABLE_USERS)->set('time = NOW()')->set('zipname = ' . $this->_db->q($zipname))->where('uuserid = ' . $this->_user->get('id'));
             $this->_db->setQuery($query);
         } else {
             $query = $this->_db->getQuery(true)->insert(_JOOM_TABLE_USERS)->set('uuserid = ' . $this->_user->get('id'))->set('time    = NOW()')->set('zipname = ' . $this->_db->q($zipname));
             $this->_db->setQuery($query);
         }
     } else {
         $query = $this->_db->getQuery(true)->insert(_JOOM_TABLE_USERS)->set('time = NOW()')->set('zipname = ' . $this->_db->q($zipname));
         $this->_db->setQuery($query);
     }
     $this->_db->query();
     $this->_mainframe->setUserState('joom.favourites.zipname', $zipname);
     // Message about new zip download
     if (!$this->_user->get('username')) {
         $username = JText::_('COM_JOOMGALLERY_COMMON_GUEST');
     } else {
         $username = $this->_config->get('jg_realname') ? $this->_user->get('name') : $this->_user->get('username');
     }
     if ($this->_config->get('jg_msg_zipdownload')) {
         $imagefiles = implode(",\n", $files);
         require_once JPATH_COMPONENT . '/helpers/messenger.php';
         $messenger = new JoomMessenger();
         $message = array('subject' => JText::_('COM_JOOMGALLERY_MESSAGE_NEW_ZIPDOWNLOAD_SUBJECT'), 'body' => JText::sprintf('COM_JOOMGALLERY_MESSAGE_NEW_ZIPDOWNLOAD_BODY', $zipname, $username, $imagefiles), 'mode' => 'zipdownload');
         $messenger->send($message);
     }
     return true;
 }
예제 #3
0
 /**
  * Creates thumbnail and detail image for an image file
  *
  * @param   string  $source         The source file for which the thumbnail and the detail image shall be created
  * @param   string  $filename       The file name for the created files
  * @param   boolean $is_in_original Determines whether the source file is already in the original images folders
  * @param   boolean $delete_source  Determines whether the source file shall be deleted after the procedure
  * @return  boolean True on success, false otherwise
  * @since   1.5.7
  */
 protected function resizeImage($source, $filename, $is_in_original = true, $delete_source = false)
 {
     if (!getimagesize($source)) {
         // getimagesize didn't find a valid image
         $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_INVALID_IMAGE_FILE') . '<br />';
         $this->debug = true;
         return false;
     }
     // Check the possible available memory for image resizing.
     // If not available echo error message and return false
     $tag = JFile::getExt($source);
     if (!$this->checkMemory($source, $tag)) {
         $this->debug = true;
         return false;
     }
     // Create thumb
     $return = JoomFile::resizeImage($this->_debugoutput, $source, $this->_ambit->getImg('thumb_path', $filename, null, $this->catid), $this->_config->get('jg_useforresizedirection'), $this->_config->get('jg_thumbwidth'), $this->_config->get('jg_thumbheight'), $this->_config->get('jg_thumbcreation'), $this->_config->get('jg_thumbquality'), false, $this->_config->get('jg_cropposition'));
     if (!$return) {
         $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_THUMBNAIL_NOT_CREATED', $this->_ambit->getImg('thumb_path', $filename, null, $this->catid)) . '<br />';
         $this->debug = true;
         return false;
     }
     $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_THUMBNAIL_CREATED') . '<br />';
     // Optionally create detail image
     $detail_image_created = false;
     if ($this->_config->get('jg_resizetomaxwidth') && ($this->_site && $this->_config->get('jg_special_gif_upload') == 0 || !$this->_mainframe->getUserStateFromRequest('joom.upload.create_special_gif', 'create_special_gif', false, 'bool') || $tag != 'gif' && $tag != 'png')) {
         $return = JoomFile::resizeImage($this->_debugoutput, $source, $this->_ambit->getImg('img_path', $filename, null, $this->catid), false, $this->_config->get('jg_maxwidth'), false, $this->_config->get('jg_thumbcreation'), $this->_config->get('jg_picturequality'), true, 0);
         if (!$return) {
             $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_IMG_NOT_CREATED', $this->_ambit->getImg('img_path', $filename, null, $this->catid)) . '<br />';
             $this->debug = true;
             return false;
         }
         $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_RESIZED_TO_MAXWIDTH') . '<br />';
         $detail_image_created = true;
     }
     $delete_original = $this->_mainframe->getUserStateFromRequest('joom.upload.delete_original', 'original_delete', false, 'bool');
     $delete_original = $this->_site && $this->_config->get('jg_delete_original_user') == 1 || $this->_site && $this->_config->get('jg_delete_original_user') == 2 && $delete_original || !$this->_site && $this->_config->get('jg_delete_original') == 1 || !$this->_site && $this->_config->get('jg_delete_original') == 2 && $delete_original;
     if ($delete_original && !$is_in_original && $delete_source || $delete_original && $is_in_original) {
         if ($detail_image_created) {
             // Remove image from originals if chosen in backend
             if (JFile::delete($source)) {
                 $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_ORIGINAL_DELETED') . '<br />';
             } else {
                 $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_DELETING_ORIGINAL', $this->_ambit->getImg('orig_path', $filename, null, $this->catid)) . ' ' . JText::_('COM_JOOMGALLERY_COMMON_CHECK_PERMISSIONS') . '<br />';
                 $this->debug = true;
                 return false;
             }
         } else {
             // Move original image to detail images folder if original image shall be deleted and detail image wasn't resized
             $return = JFile::move($source, $this->_ambit->getImg('img_path', $filename, null, $this->catid));
             if (!$return) {
                 $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_MOVING', $this->_ambit->getImg('img_path', $filename, null, $this->catid)) . '<br />';
                 $this->debug = true;
                 return false;
             }
         }
     } else {
         if (!$detail_image_created) {
             // Copy original image into detail images folder if original image shouldn't be deleted and detail image wasn't resized
             $return = JFile::copy($source, $this->_ambit->getImg('img_path', $filename, null, $this->catid));
             if (!$return) {
                 $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_COPYING', $this->_ambit->getImg('img_path', $filename, null, $this->catid)) . '<br />';
                 $this->debug = true;
                 return false;
             }
             if ($delete_original && !$is_in_original && !$delete_source) {
                 if (JFile::delete($source)) {
                     $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_ORIGINAL_DELETED') . '<br />';
                 } else {
                     $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_DELETING_ORIGINAL', $this->_ambit->getImg('orig_path', $filename, null, $this->catid)) . ' ' . JText::_('COM_JOOMGALLERY_COMMON_CHECK_PERMISSIONS') . '<br />';
                     $this->debug = true;
                     return false;
                 }
             }
         }
     }
     // Set permissions of detail image
     if ($detail_image_created) {
         $return = JoomFile::chmod($this->_ambit->getImg('img_path', $filename, null, $this->catid), '0644');
         /*if(!$return)
           {
             $this->_debugoutput .= $this->_ambit->getImg('img_path', $filename, null, $this->catid).' '.JText::_('COM_JOOMGALLERY_COMMON_CHECK_PERMISSIONS').'<br />';
             $this->debug        = true;
             return false;
           }*/
     }
     if (!$delete_original && !$is_in_original && !$delete_source) {
         // Copy source file to orginal images folder if original image shouldn't be deleted and if it's not already there
         $return = JFile::copy($source, $this->_ambit->getImg('orig_path', $filename, null, $this->catid));
         if (!$return) {
             $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_COPYING', $this->_ambit->getImg('orig_path', $filename, null, $this->catid)) . '<br />';
             $this->debug = true;
             return false;
         }
     } else {
         if (!$delete_original && !$is_in_original && $delete_source) {
             // Move source file to orginal images folder if original image shall be deleted and if it's not already there
             $return = JFile::move($source, $this->_ambit->getImg('orig_path', $filename, null, $this->catid));
             if (!$return) {
                 $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_MOVING', $this->_ambit->getImg('orig_path', $filename, null, $this->catid)) . '<br />';
                 $this->debug = true;
                 return false;
             }
         }
     }
     return true;
 }