/** * Method to attach a JForm object to the field. * Catch upload files when form setup. * * @param object &$element The JXmlElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * * @return boolean True on success. */ public function setup(SimpleXMLElement $element, $value, $group = null) { parent::setup($element, $value, $group); if (JRequest::getVar($this->element['name'] . '_delete') == 1) { $this->value = ''; } else { // Upload Image // =============================================== if (isset($_FILES['jform']['name']['profile'])) { foreach ($_FILES['jform']['name']['profile'] as $key => $var) { if (!$var) { continue; } // Get Field Attr $width = $this->element['save_width'] ? $this->element['save_width'] : 800; $height = $this->element['save_height'] ? $this->element['save_height'] : 800; // Build File name $src = $_FILES['jform']['tmp_name']['profile'][$key]; $var = explode('.', $var); $date = JFactory::getDate('now', JFactory::getConfig()->get('offset')); $name = md5((string) $date . $width . $height . $src) . '.' . array_pop($var); $url = "images/cck/{$date->year}/{$date->month}/{$date->day}/" . $name; // A Event for extend. JFactory::getApplication()->triggerEvent('onCCKEngineUploadImage', array(&$url, &$this, &$this->element)); $dest = JPATH_ROOT . '/' . $url; // Upload First JFile::upload($src, $dest); // Resize image $img = new JImage(); $img->loadFile(JPATH_ROOT . '/' . $url); $img = $img->resize($width, $height); switch (array_pop($var)) { case 'gif': $type = IMAGETYPE_GIF; break; case 'png': $type = IMAGETYPE_PNG; break; default: $type = IMAGETYPE_JPEG; break; } // save $img->toFile($dest, $type, array('quality' => 85)); // Set in Value $this->value = $url; } } } return true; }
/** * Resize an image, auto catch it from remote host and generate a new thumb in cache dir. * * @param string $url Image URL, recommend a absolute URL. * @param integer $width Image width, do not include 'px'. * @param integer $height Image height, do not include 'px'. * @param boolean $zc Crop or not. * @param integer $q Image quality * @param string $file_type File type. * * @return string The cached thumb URL. */ public static function resize($url = null, $width = 100, $height = 100, $zc = 0, $q = 85, $file_type = 'jpg') { if (!$url) { return self::getDefaultImage($width, $height, $zc, $q, $file_type); } $path = self::getImagePath($url); try { $img = new JImage(); if (JFile::exists($path)) { $img->loadFile($path); } else { return self::getDefaultImage($width, $height, $zc, $q, $file_type); } // get Width Height $imgdata = JImage::getImageFileProperties($path); // set save data if ($file_type != 'png' && $file_type != 'gif') { $file_type = 'jpg'; } $file_name = md5($url . $width . $height . $zc . $q . implode('', (array) $imgdata)) . '.' . $file_type; $file_path = self::$cache_path . DS . $file_name; $file_url = trim(self::$cache_url, '/') . '/' . $file_name; // img exists? if (JFile::exists($file_path)) { return $file_url; } // crop if ($zc) { $img = self::crop($img, $width, $height, $imgdata); } // resize $img = $img->resize($width, $height); // save switch ($file_type) { case 'gif': $type = IMAGETYPE_GIF; break; case 'png': $type = IMAGETYPE_PNG; break; default: $type = IMAGETYPE_JPEG; break; } JFolder::create(self::$cache_path); $img->toFile($file_path, $type, array('quality' => $q)); return $file_url; } catch (Exception $e) { if (JDEBUG) { echo $e->getMessage(); } return self::getDefaultImage($width, $height, $zc, $q, $file_type); } }
protected function _resize($imagePath, $opts = null) { $imagePath = urldecode($imagePath); # start configuration $cacheFolder = $this->cache_folder . '/'; # path to your cache folder, must be writeable by web server // s2s: use $this->cache_folder //$remoteFolder = $cacheFolder.'remote/'; # path to the folder you wish to download remote images into $defaults = array('crop' => false, 'scale' => false, 'thumbnail' => false, 'maxOnly' => false, 'canvas-color' => 'transparent', 'output-filename' => false, 'quality' => 100, 'cache_http_minutes' => 20); $opts = array_merge($defaults, $opts); $purl = parse_url($imagePath); $finfo = pathinfo($imagePath); $ext = $finfo['extension']; //echo '<pre>';var_dump($purl);var_dump($finfo);die; //var_dump($finfo);die; # check for remote image.. if (isset($purl['scheme']) && ($purl['scheme'] == 'http' || $purl['scheme'] == 'https')) { # grab the image, and cache it so we have something to work with.. list($filename) = explode('?', $finfo['basename']); $local_filepath = $cacheFolder . 'remote/' . $filename; $download_image = true; if (file_exists($_SERVER['DOCUMENT_ROOT'] . $local_filepath)) { if (filemtime($local_filepath) < strtotime('+' . $opts['cache_http_minutes'] . ' minutes')) { $download_image = false; } } if ($download_image == true) { $img = file_get_contents($imagePath); file_put_contents($local_filepath, $img); } $imagePath = $local_filepath; } //echo $ext.' '.$imagePath;die; $absoluteImagePath = JPath::clean(JPATH_ROOT . '/' . $imagePath); //echo $absoluteImagePath;die; /*s2s: maxOnly FIX - start*/ if ($opts['maxOnly']) { $imagesize = getimagesize($absoluteImagePath); //echo'<pre>';var_dump($imagesize);die; if (isset($opts['w'])) { if ($opts['w'] > $imagesize[0]) { $opts['w'] = $imagesize[0]; } } if (isset($opts['h'])) { if ($opts['h'] > $imagesize[1]) { $opts['h'] = $imagesize[1]; } } $opts['maxOnly'] = false; } // check if original size is less than option size if ($opts['crop']) { // fix crop: in some cases doesn't work (in exec mode) $imagesize = getimagesize($absoluteImagePath); // 0 => width, 1 => height //echo'<pre>';var_dump($imagesize);die; if ($imagesize[0] > $imagesize[1] && $imagesize[0] / $imagesize[1] < $opts['w'] / $opts['h'] || $imagesize[0] < $imagesize[1] && $imagesize[0] / $imagesize[1] > $opts['w'] / $opts['h']) { $opts['crop'] = true; $opts['resize'] = TRUE; } } /*s2s - end*/ //$path_to_convert = 'convert'; # this could be something like /usr/bin/convert or /opt/local/share/bin/convert //s2s ORIGINALE //$path_to_convert = $this->imagick_path_to_convert; // s2s imagick convert path from config ## you shouldn't need to configure anything else beyond this point list($orig_w, $orig_h) = getimagesize($absoluteImagePath); if (isset($opts['w'])) { if (stripos($opts['w'], '%') !== false) { $w = (int) ((double) str_replace('%', '', $opts['w']) / 100 * $orig_w); } else { $w = (int) $opts['w']; } } if (isset($opts['h'])) { if (stripos($opts['h'], '%') !== false) { $h = (int) ((double) str_replace('%', '', $opts['h']) / 100 * $orig_h); } else { $h = (int) $opts['h']; } } if (!isset($opts['w']) && !isset($opts['h'])) { list($w, $h) = array($orig_w, $orig_h); } //$filename = md5_file($absoluteImagePath); //$imageExt = JFile::getExt($absoluteImagePaths); $imageName = preg_replace('/\\.' . $ext . '$/', '', JFile::getName($absoluteImagePath)); $imageNameNew = $imageName . '_w' . $w . 'xh' . $h; if (!empty($w) and !empty($h)) { $imageNameNew = $imageName . '_w' . $w . '_h' . $h . (isset($opts['crop']) && $opts['crop'] == true ? "_cp" : "") . (isset($opts['scale']) && $opts['scale'] == true ? "_sc" : "") . '_q' . $opts['quality']; } elseif (!empty($w)) { $imageNameNew = $imageName . '_w' . $w . '_q' . $opts['quality']; } elseif (!empty($h)) { $imageNameNew = $imageName . '_h' . $h . '_q' . $opts['quality']; } else { return false; } //$absoluteImagePathNew = str_replace($imageName.'.'.$ext, $imageNameNew.'.'.$ext, $absoluteImagePath);//JPath::clean(JPATH_ROOT.'/'.$relativePathNew); $absoluteImagePathNew = JPath::clean(JPATH_ROOT . '/' . $cacheFolder . $imageNameNew . '.' . $ext); $relativeImagePathNew = preg_replace('/\\\\/', '/', str_replace(JPATH_ROOT, "", $absoluteImagePathNew)); if (JFile::exists($absoluteImagePathNew)) { $imageDateOrigin = filemtime($absoluteImagePath); $imageDateThumb = filemtime($absoluteImagePathNew); $clearCache = $imageDateOrigin > $imageDateThumb; if ($clearCache == false) { return $relativeImagePathNew; } } //echo $relativeImagePathNew;die; if ($this->imagick_process == 'jimage' && class_exists('JImage')) { // s2s Use Joomla JImage class (GD) if (empty($w)) { $w = 0; } if (empty($h)) { $h = 0; } //echo $imagePath;die; // Keep proportions if w or h is not defined list($width, $height) = getimagesize($absoluteImagePath); //echo $width.' '.$height;die; if (!$w) { $w = $h / $height * $width; } if (!$h) { $h = $w / $width * $height; } //echo $imagePath;die; //echo (JURI::root().$imagePath);die; // http://stackoverflow.com/questions/10842734/how-resize-image-in-joomla try { $image = new JImage(); $image->loadFile($absoluteImagePath); //echo'<pre>';var_dump($image);die; } catch (Exception $e) { return str_replace(JPATH_ROOT, "", $absoluteImagePath); // "Attempting to load an image of unsupported type: image/x-ms-bmp" } if ($opts['crop'] === true) { $rw = $w; $rh = $h; if ($width / $height < $rw / $rh) { $rw = $w; $rh = $rw / $width * $height; } else { $rh = $h; $rw = $rh / $height * $width; } $resizedImage = $image->resize($rw, $rh)->crop($w, $h); } else { $resizedImage = $image->resize($w, $h); } $properties = JImage::getImageFileProperties($absoluteImagePath); // fix compression level must be 0 through 9 (in case of png) $quality = $opts['quality']; if ($properties->type == IMAGETYPE_PNG) { $quality = round(9 - $quality * 9 / 100); // 100 quality = 0 compression, 0 quality = 9 compression } //echo '<pre>';var_dump($properties);die; $resizedImage->toFile($absoluteImagePathNew, $properties->type, array('quality' => $quality)); } //echo $relativeImagePathNew;die; # return cache file path return $relativeImagePathNew; }
function upload_image() { $user = JFactory::getUser(); JFactory::getDocument()->setMimeEncoding('application/json'); if ($user->guest) { echo json_encode(array('error' => 'no permissions')); return JFactory::getApplication()->close(); } jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $file = JRequest::getVar('Filedata', '', 'files', 'array'); $extension = JRequest::getVar('extension', null); //mime_content_type() if (($imginfo = getimagesize($file['tmp_name'])) === false) { echo json_encode(array('error' => 'not an image')); return JFactory::getApplication()->close(); } $params = JComponentHelper::getParams('com_media'); $allowed_mime = explode(',', $params->get('upload_mime')); $illegal_mime = explode(',', $params->get('upload_mime_illegal')); if (function_exists('finfo_open')) { $finfo = finfo_open(FILEINFO_MIME); $type = finfo_file($finfo, $file['tmp_name']); if (strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) { echo json_encode(array('error' => 'dont try to f**k the server')); return JFactory::getApplication()->close(); } finfo_close($finfo); } elseif (function_exists('mime_content_type')) { $type = mime_content_type($file['tmp_name']); if (strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) { echo json_encode(array('error' => 'COM_KSM_ERROR_WARNINVALID_MIME')); return JFactory::getApplication()->close(); } } elseif (!$user->authorise('core.manage')) { echo json_encode(array('error' => 'COM_KSM_ERROR_WARNNOTADMIN')); return JFactory::getApplication()->close(); } $to = JRequest::getString('to', ''); $folder = JRequest::getString('folder', ''); $path = JPATH_ROOT; $to = explode("/", $to); foreach ($to as $s) { $path = $path . DS . $s; if (!JFolder::exists($path)) { if (!JFolder::create($path)) { echo json_encode(array('error' => 'COM_KSM_ERROR_CREATEDIR')); return JFactory::getApplication()->close(); } } } try { $imageObject = new JImage(); $imageObject->loadFile($file['tmp_name']); } catch (Exception $e) { echo json_encode(array('error' => $e->getMessage())); return JFactory::getApplication()->close(); } $pathinfo = pathinfo($file['name']); $fileName = $path . DS . microtime(true) . '.' . $pathinfo['extension']; try { $imageObject->toFile($fileName, IMAGETYPE_JPEG, array('quality', 100)); //$imageObject->save($fileName, 100); } catch (Exception $e) { echo json_encode(array('error' => $e->getMessage())); return JFactory::getApplication()->close(); } $url = KSMedia::resizeImage(basename($fileName), $folder, null, null, null, $extension); $model = $this->getModel('media'); $model->form = 'images'; $item = new stdClass(); $table = $model->getTable('Files'); $table->media_type = 'images'; $table->filename = str_replace(JPATH_ROOT, '', $fileName); $table->folder = $folder; $table->id = '{id}'; $item->images = array(0 => $table); $form = $model->getForm(); $form->setFieldAttribute('images', 'extension', $extension); $form->bind($item); $html = $form->getInput('images'); echo json_encode(array('error' => '', 'filename' => str_replace(JPATH_ROOT, '', $fileName), 'url' => $url, 'html' => $html)); JFactory::getApplication()->close(); }
public static function createThumb($path, $width = 100, $height = 100, $crop = 2, $cachefolder = 'hgimages', $external = 0) { $myImage = new JImage(); if (!$external) { $myImage->loadFile(JPATH_SITE . DS . $path); } else { $myImage->loadFile($path); } if ($myImage->isLoaded()) { // $filename = end(explode('/', $path)); $filename = JFile::getName($path); $filefolder = substr(md5(self::getFolderPath($path)), 1, 10); $newfilename = $width . 'x' . $height . 'x' . $crop . '_' . $filefolder . '_' . JFile::makeSafe($filename); $hgimages = JPATH_CACHE . '/' . $cachefolder . '/'; if (!JFolder::exists($hgimages)) { JFolder::create($hgimages); } $fileExists = JFile::exists($hgimages . $newfilename); if (!$fileExists) { switch ($crop) { // Case for self::CROP case 4: $resizedImage = $myImage->crop($width, $height, null, null, true); break; // Case for self::CROP_RESIZE // Case for self::CROP_RESIZE case 5: $resizedImage = $myImage->cropResize($width, $height, true); break; default: $resizedImage = $myImage->resize($width, $height, true, $crop); break; } $properties = $myImage->getImageFileProperties($path); $mime = $properties->mime; if ($mime == 'image/jpeg') { $type = IMAGETYPE_JPEG; } elseif ($mime = 'image/png') { $type = IMAGETYPE_PNG; } elseif ($mime = 'image/gif') { $type = IMAGETYPE_GIF; } $resizedImage->toFile($hgimages . $newfilename, $type); } return $newfilename; } else { return "My file is not loaded"; } }
public static function createThumb($path, $width = 100, $height = 100, $crop = 2) { $myImage = new JImage(); $myImage->loadFile(JPATH_SITE . DS . $path); if ($myImage->isLoaded()) { // $filename = end(explode('/', $path)); $filename = JFile::getName($path); $filefolder = substr(md5(self::getFolderPath($path)), 1, 10); $newfilename = $width . 'x' . $height . '_' . $filefolder . '_' . JFile::makeSafe($filename); $fileExists = JFile::exists(JPATH_CACHE . '/' . $newfilename); if (!$fileExists) { $resizedImage = $myImage->resize($width, $height, true, $crop); $properties = $myImage->getImageFileProperties($path); $mime = $properties->mime; if ($mime == 'image/jpeg') { $type = IMAGETYPE_JPEG; } elseif ($mime = 'image/png') { $type = IMAGETYPE_PNG; } elseif ($mime = 'image/gif') { $type = IMAGETYPE_GIF; } $resizedImage->toFile(JPATH_CACHE . '/' . $newfilename, $type); } return $newfilename; } else { return "My file is not loaded"; } }
/** * Create a thumbnail from an image file. * * <code> * $myFile = "/tmp/myfile.jpg"; * * $options = array( * "destination" => "image/mypic.jpg", * "width" => 200, * "height" => 200, * "scale" => JImage::SCALE_INSIDE * ); * * $file = new PrismFileImage($myFile); * $file->createThumbnail($options); * * </code> * * @param array $options Some options used in the process of generating thumbnail. * * @throws \InvalidArgumentException * @throws \RuntimeException * * @return string A location to the new file. */ public function createThumbnail($options) { $width = ArrayHelper::getValue($options, "width", 100); $height = ArrayHelper::getValue($options, "height", 100); $scale = ArrayHelper::getValue($options, "scale", \JImage::SCALE_INSIDE); $destination = ArrayHelper::getValue($options, "destination"); if (!$destination) { throw new \InvalidArgumentException(\JText::_("LIB_PRISM_ERROR_INVALID_FILE_DESTINATION")); } // Generate thumbnail. $image = new \JImage(); $image->loadFile($this->file); if (!$image->isLoaded()) { throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND', $this->file)); } // Resize the file as a new object $thumb = $image->resize($width, $height, true, $scale); $fileName = basename($this->file); $ext = \JString::strtolower(\JFile::getExt(\JFile::makeSafe($fileName))); switch ($ext) { case "gif": $type = IMAGETYPE_GIF; break; case "png": $type = IMAGETYPE_PNG; break; case IMAGETYPE_JPEG: default: $type = IMAGETYPE_JPEG; } $thumb->toFile($destination, $type); return $destination; }
/** * Resize an image, auto catch it from remote host and generate a new thumb in cache dir. * * @param string $url Image URL, recommend a absolute URL. * @param integer $width Image width, do not include 'px'. * @param integer $height Image height, do not include 'px'. * @param int $method Crop or not. * @param integer $q Image quality * @param string $file_type File type. * * @return string The cached thumb URL. */ public function resize($url = null, $width = 100, $height = 100, $method = \JImage::SCALE_INSIDE, $q = 85, $file_type = 'jpg') { if (!$url) { return $this->getDefaultImage($width, $height, $method, $q, $file_type); } $path = $this->getImagePath($url); try { $img = new \JImage(); if (\JFile::exists($path)) { $img->loadFile($path); } else { return $this->getDefaultImage($width, $height, $method, $q, $file_type); } // If file type not png or gif, use jpg as default. if ($file_type != 'png' && $file_type != 'gif') { $file_type = 'jpg'; } // Using md5 hash $handler = $this->hashHandler; $file_name = $handler($url . $width . $height . $method . $q) . '.' . $file_type; $file_path = $this->config['path.cache'] . '/' . $file_name; $file_url = trim($this->config['url.cache'], '/') . '/' . $file_name; // Img exists? if (\JFile::exists($file_path)) { return $file_url; } // Crop if ($method === true) { $method = \JImage::CROP_RESIZE; } elseif ($method === false) { $method = \JImage::SCALE_INSIDE; } $img = $img->generateThumbs($width . 'x' . $height, $method); // Save switch ($file_type) { case 'gif': $type = IMAGETYPE_GIF; break; case 'png': $type = IMAGETYPE_PNG; break; default: $type = IMAGETYPE_JPEG; break; } // Create folder if (!is_dir(dirname($file_path))) { \JFolder::create(dirname($file_path)); } $img[0]->toFile($file_path, $type, array('quality' => $q)); return $file_url; } catch (\Exception $e) { if (JDEBUG) { echo $e->getMessage(); } return $this->getDefaultImage($width, $height, $method, $q, $file_type); } }
public static function getProportion($path) { $myImage = new JImage(); $imgPath = JPATH_SITE . DS . $path; $myImage->loadFile($imgPath); if ($myImage->isLoaded()) { $properties = $myImage->getImageFileProperties($imgPath); return $properties->height / $properties->width * 100; } else { return; } }
/** * Plugin that manipulate uploaded images * * @param string $context The context of the content being passed to the plugin. * @param object &$object_file The file object. * * @return object The file object. */ public function onContentAfterSave($context, &$object_file) { // Are we in the right context? if ($context != 'com_media.file') { return; } $file = pathinfo($object_file->filepath); // Skip if the pass through keyword is set if (preg_match('/' . $this->params->get('passthrough') . '_/', $file['filename'])) { return; } $image = new JImage(); // Load the file $image->loadFile($object_file->filepath); // Get the properties $properties = $image->getImageFileProperties($object_file->filepath); // Skip if the width is less or equal to the required if ($properties->width <= $this->params->get('maxwidth')) { return; } // Get the image type if (preg_match('/jp(e)g/', mb_strtolower($properties->mime))) { $imageType = 'IMAGETYPE_JPEG'; } if (preg_match('/gif/', mb_strtolower($properties->mime))) { $imageType = 'IMAGETYPE_GIF'; } if (preg_match('/png/', mb_strtolower($properties->mime))) { $imageType = 'IMAGETYPE_PNG'; } // Resize the image $image->resize($this->params->get('maxwidth'), '', false); // Overwrite the file $image->toFile($object_file->filepath, $imageType, array('quality' => $this->params->get('quality'))); return $object_file; }
/** * Upload a pitch image. * * @param array $image * * @throws Exception * * @return array */ public function uploadPitchImage($image) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $uploadedFile = JArrayHelper::getValue($image, 'tmp_name'); $uploadedName = JArrayHelper::getValue($image, 'name'); $errorCode = JArrayHelper::getValue($image, 'error'); // Load parameters. $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ $destFolder = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $params->get("images_directory", "images/crowdfunding")); $tmpFolder = $app->get("tmp_path"); // Joomla! media extension parameters $mediaParams = JComponentHelper::getParams("com_media"); /** @var $mediaParams Joomla\Registry\Registry */ jimport("itprism.file"); jimport("itprism.file.uploader.local"); jimport("itprism.file.validator.size"); jimport("itprism.file.validator.image"); jimport("itprism.file.validator.server"); $file = new ITPrismFile(); // Prepare size validator. $KB = 1024 * 1024; $fileSize = (int) $app->input->server->get('CONTENT_LENGTH'); $uploadMaxSize = $mediaParams->get("upload_maxsize") * $KB; $sizeValidator = new ITPrismFileValidatorSize($fileSize, $uploadMaxSize); // Prepare server validator. $serverValidator = new ITPrismFileValidatorServer($errorCode, array(UPLOAD_ERR_NO_FILE)); // Prepare image validator. $imageValidator = new ITPrismFileValidatorImage($uploadedFile, $uploadedName); // Get allowed mime types from media manager options $mimeTypes = explode(",", $mediaParams->get("upload_mime")); $imageValidator->setMimeTypes($mimeTypes); // Get allowed image extensions from media manager options $imageExtensions = explode(",", $mediaParams->get("image_extensions")); $imageValidator->setImageExtensions($imageExtensions); $file->addValidator($sizeValidator)->addValidator($imageValidator)->addValidator($serverValidator); // Validate the file if (!$file->isValid()) { throw new RuntimeException($file->getError()); } // Generate temporary file name $ext = JString::strtolower(JFile::makeSafe(JFile::getExt($image['name']))); jimport("itprism.string"); $generatedName = new ITPrismString(); $generatedName->generateRandomString(32); $tmpDestFile = $tmpFolder . DIRECTORY_SEPARATOR . $generatedName . "." . $ext; // Prepare uploader object. $uploader = new ITPrismFileUploaderLocal($uploadedFile); $uploader->setDestination($tmpDestFile); // Upload temporary file $file->setUploader($uploader); $file->upload(); // Get file $tmpDestFile = $file->getFile(); if (!is_file($tmpDestFile)) { throw new Exception('COM_CROWDFUNDING_ERROR_FILE_CANT_BE_UPLOADED'); } // Resize image $image = new JImage(); $image->loadFile($tmpDestFile); if (!$image->isLoaded()) { throw new Exception(JText::sprintf('COM_CROWDFUNDING_ERROR_FILE_NOT_FOUND', $tmpDestFile)); } $imageName = $generatedName . "_pimage.png"; $imageFile = JPath::clean($destFolder . DIRECTORY_SEPARATOR . $imageName); // Create main image $width = $params->get("pitch_image_width", 600); $height = $params->get("pitch_image_height", 400); $image->resize($width, $height, false); $image->toFile($imageFile, IMAGETYPE_PNG); // Remove the temporary if (is_file($tmpDestFile)) { JFile::delete($tmpDestFile); } return $imageName; }
/** * Upload an image * * @param array $image Array with information about uploaded file. * * @throws RuntimeException * @return array */ public function uploadImage($image) { $app = JFactory::getApplication(); /** @var $app JApplicationAdministrator */ $uploadedFile = Joomla\Utilities\ArrayHelper::getValue($image, 'tmp_name'); $uploadedName = Joomla\Utilities\ArrayHelper::getValue($image, 'name'); $errorCode = Joomla\Utilities\ArrayHelper::getValue($image, 'error'); $tmpFolder = $app->get("tmp_path"); /** @var $params Joomla\Registry\Registry */ $params = JComponentHelper::getParams($this->option); $destFolder = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $params->get("images_directory", "/images/profiles")); $options = array("width" => $params->get("image_width"), "height" => $params->get("image_height"), "small_width" => $params->get("image_small_width"), "small_height" => $params->get("image_small_height"), "square_width" => $params->get("image_square_width"), "square_height" => $params->get("image_square_height"), "icon_width" => $params->get("image_icon_width"), "icon_height" => $params->get("image_icon_height")); // Joomla! media extension parameters /** @var $mediaParams Joomla\Registry\Registry */ $mediaParams = JComponentHelper::getParams("com_media"); jimport("itprism.file"); jimport("itprism.file.uploader.local"); jimport("itprism.file.validator.size"); jimport("itprism.file.validator.image"); jimport("itprism.file.validator.server"); $file = new Prism\File\File(); // Prepare size validator. $KB = 1024 * 1024; $fileSize = (int) $app->input->server->get('CONTENT_LENGTH'); $uploadMaxSize = $mediaParams->get("upload_maxsize") * $KB; // Prepare file size validator $sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize); // Prepare server validator. $serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE)); // Prepare image validator. $imageValidator = new Prism\File\Validator\Image($uploadedFile, $uploadedName); // Get allowed mime types from media manager options $mimeTypes = explode(",", $mediaParams->get("upload_mime")); $imageValidator->setMimeTypes($mimeTypes); // Get allowed image extensions from media manager options $imageExtensions = explode(",", $mediaParams->get("image_extensions")); $imageValidator->setImageExtensions($imageExtensions); $file->addValidator($sizeValidator)->addValidator($imageValidator)->addValidator($serverValidator); // Validate the file if (!$file->isValid()) { throw new RuntimeException($file->getError()); } // Generate temporary file name $ext = JFile::makeSafe(JFile::getExt($image['name'])); $generatedName = new Prism\String(); $generatedName->generateRandomString(32); $tmpDestFile = $tmpFolder . DIRECTORY_SEPARATOR . $generatedName . "." . $ext; // Prepare uploader object. $uploader = new Prism\File\Uploader\Local($uploadedFile); $uploader->setDestination($tmpDestFile); // Upload temporary file $file->setUploader($uploader); $file->upload(); // Get file $tmpSourceFile = $file->getFile(); if (!is_file($tmpSourceFile)) { throw new RuntimeException('COM_SOCIALCOMMUNITY_ERROR_FILE_CANT_BE_UPLOADED'); } // Generate file names for the image files. $generatedName->generateRandomString(32); $imageName = $generatedName . "_image.png"; $smallName = $generatedName . "_small.png"; $squareName = $generatedName . "_square.png"; $iconName = $generatedName . "_icon.png"; // Resize image $image = new JImage(); $image->loadFile($tmpSourceFile); if (!$image->isLoaded()) { throw new RuntimeException(JText::sprintf('COM_SOCIALCOMMUNITY_ERROR_FILE_NOT_FOUND', $tmpSourceFile)); } $imageFile = $destFolder . DIRECTORY_SEPARATOR . $imageName; $smallFile = $destFolder . DIRECTORY_SEPARATOR . $smallName; $squareFile = $destFolder . DIRECTORY_SEPARATOR . $squareName; $iconFile = $destFolder . DIRECTORY_SEPARATOR . $iconName; // Create profile picture $width = Joomla\Utilities\ArrayHelper::getValue($options, "image_width", 200); $height = Joomla\Utilities\ArrayHelper::getValue($options, "image_height", 200); $image->resize($width, $height, false); $image->toFile($imageFile, IMAGETYPE_PNG); // Create small profile picture $width = Joomla\Utilities\ArrayHelper::getValue($options, "small_width", 100); $height = Joomla\Utilities\ArrayHelper::getValue($options, "small_height", 100); $image->resize($width, $height, false); $image->toFile($smallFile, IMAGETYPE_PNG); // Create square picture $width = Joomla\Utilities\ArrayHelper::getValue($options, "square_width", 50); $height = Joomla\Utilities\ArrayHelper::getValue($options, "square_height", 50); $image->resize($width, $height, false); $image->toFile($squareFile, IMAGETYPE_PNG); // Create icon picture $width = Joomla\Utilities\ArrayHelper::getValue($options, "icon_width", 24); $height = Joomla\Utilities\ArrayHelper::getValue($options, "icon_height", 24); $image->resize($width, $height, false); $image->toFile($iconFile, IMAGETYPE_PNG); // Remove the temporary file if (JFile::exists($tmpSourceFile)) { JFile::delete($tmpSourceFile); } return $names = array("image" => $imageName, "image_small" => $smallName, "image_icon" => $iconName, "image_square" => $squareName); }
function uploadImages($file, $currentImage = null) { if ($file) { $maxSize = 2 * 1024 * 1024; $arr = array('image/jpeg', 'image/jpg', 'image/bmp', 'image/gif', 'image/png', 'image/ico'); // Create folder $tzFolder = 'tz_portfolio'; $tzUserFolder = 'users'; $tzFolderPath = JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $tzFolder; $tzUserFolderPath = $tzFolderPath . DIRECTORY_SEPARATOR . $tzUserFolder; if (!JFolder::exists($tzFolderPath)) { JFolder::create($tzFolderPath); if (!JFile::exists($tzFolderPath . DIRECTORY_SEPARATOR . 'index.html')) { JFile::write($tzFolderPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>')); } } if (JFolder::exists($tzFolderPath)) { if (!JFolder::exists($tzUserFolderPath)) { JFolder::create($tzUserFolderPath); if (!JFile::exists($tzUserFolderPath . DIRECTORY_SEPARATOR . 'index.html')) { JFile::write($tzUserFolderPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>')); } } } if (is_array($file)) { foreach ($file as $key => $val) { if (is_array($val)) { foreach ($val as $key2 => $val2) { $file[$key] = $val2; } } } //Upload image if (in_array($file['type'], $arr)) { if ($file['size'] <= $maxSize) { $desFileName = 'user_' . time() . uniqid() . '.' . JFile::getExt($file['name']); $desPath = $tzUserFolderPath . DIRECTORY_SEPARATOR . $desFileName; if (JFile::exists($file['tmp_name'])) { if (!JFile::copy($file['tmp_name'], $desPath)) { JError::raiseNotice(300, JText::_('COM_TZ_PORTFOLIO_CAN_NOT_UPLOAD_FILE')); } $image = new JImage(); $image->loadFile($desPath); $params = JComponentHelper::getParams('com_tz_portfolio'); if ($params->get('tz_user_image_width', 100)) { $width = $params->get('tz_user_image_width', 100); } $height = ceil($image->getHeight() * $width / $image->getWidth()); $image = $image->resize($width, $height); $type = $this->_getImageType($file['name']); $image->toFile($desPath, $type); $this->deleteImages($currentImage); return 'media/' . $tzFolder . '/' . $tzUserFolder . '/' . $desFileName; } } else { JError::raiseNotice(300, JText::_('COM_TZ_PORTFOLIO_IMAGE_SIZE_TOO_LARGE')); } } else { JError::raiseNotice(300, JText::_('COM_TZ_PORTFOLIO_IMAGE_FILE_NOT_SUPPORTED')); } } else { tzportfolioimport('HTTPFetcher'); tzportfolioimport('readfile'); $image = new Services_Yadis_PlainHTTPFetcher(); $image = $image->get($file); if (in_array($image->headers['Content-Type'], $arr)) { if ($image->headers['Content-Length'] > $maxSize) { $this->deleteImages($currentImage); $desFileName = 'user_' . time() . uniqid() . '.' . str_replace('image/', '', $image->headers['Content-Type']); $desPath = $tzUserFolderPath . DIRECTORY_SEPARATOR . $desFileName; if (JFolder::exists($tzFolderPath)) { if (!JFile::write($desPath, $image->body)) { $this->setError(JText::_('COM_TZ_PORTFOLIO_CAN_NOT_UPLOAD_FILE')); return false; } return 'media/' . $tzFolder . '/' . $tzUserFolder . '/' . $desFileName; } } else { JError::raiseNotice(300, JText::_('COM_TZ_PORTFOLIO_IMAGE_SIZE_TOO_LARGE')); } } else { JError::raiseNotice(300, JText::_('COM_TZ_PORTFOLIO_IMAGE_FILE_NOT_SUPPORTED')); } } } if ($currentImage) { return $currentImage; } return ''; }
/** * Method to attach a JForm object to the field. * Catch upload files when form setup. * * @param SimpleXMLElement $element The JXmlElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * * @return boolean True on success. */ public function setup(SimpleXMLElement $element, $value, $group = null) { parent::setup($element, $value, $group); $container = \Windwalker\DI\Container::getInstance(); $input = $container->get('input'); $delete = isset($_REQUEST['jform']['profile'][$this->element['name'] . '_delete']) ? $_REQUEST['jform']['profile'][$this->element['name'] . '_delete'] : 0; if ($delete == 1) { $this->value = ''; } else { // Upload Image // =============================================== if (isset($_FILES['jform']['name']['profile'])) { foreach ($_FILES['jform']['name']['profile'] as $key => $var) { if (!$var) { continue; } // Get Field Attr $width = $this->element['save_width'] ? $this->element['save_width'] : 800; $height = $this->element['save_height'] ? $this->element['save_height'] : 800; // Build File name $src = $_FILES['jform']['tmp_name']['profile'][$key]; $var = explode('.', $var); $date = DateHelper::getDate(); $name = md5((string) $date . $width . $height . $src) . '.' . array_pop($var); $url = "images/cck/{$date->year}/{$date->month}/{$date->day}/" . $name; // A Event for extend. $container->get('event.dispatcher')->trigger('onCCKEngineUploadImage', array(&$url, &$this, &$this->element)); $dest = JPATH_ROOT . '/' . $url; // Upload First JFile::upload($src, $dest); // Resize image $img = new JImage(); $img->loadFile(JPATH_ROOT . '/' . $url); $img = $img->resize($width, $height); switch (array_pop($var)) { case 'gif': $type = IMAGETYPE_GIF; break; case 'png': $type = IMAGETYPE_PNG; break; default: $type = IMAGETYPE_JPEG; break; } // Save $img->toFile($dest, $type, array('quality' => 85)); // Set in Value $this->value = $url; // Clean cache $thumb = $this->getThumbPath(); if (is_file(JPATH_ROOT . '/' . $thumb)) { \JFile::delete(JPATH_ROOT . '/' . $thumb); } } } } return true; }
public function save($data) { $app = JFactory::getApplication(); $input = $app->input; $_data = array('id' => $data->id, 'asset_id' => $data->asset_id, 'media' => '{}'); $params = $this->getState('params'); // Get some params $mime_types = $params->get('image_mime_type', 'image/jpeg,image/gif,image/png,image/bmp'); $mime_types = explode(',', $mime_types); $file_types = $params->get('image_file_type', 'bmp,gif,jpg,jpeg,png'); $file_types = explode(',', $file_types); $file_sizes = $params->get('image_file_size', 10); $file_sizes = $file_sizes * 1024 * 1024; // Get and Process data $image_data = $input->get('jform', null, 'array'); if (isset($image_data['media'])) { if (isset($image_data['media'][$this->getName()])) { $image_data = $image_data['media']['image']; } } $media = null; if ($data->media && !empty($data->media)) { $media = new JRegistry(); $media->loadString($data->media); $media = $media->get('image'); } // Set data when save as copy article if ($input->getCmd('task') == 'save2copy' && $input->getInt('id')) { if (isset($image_data['url_remove']) && $image_data['url_remove']) { $image_data['url_remove'] = null; $image_data['url'] = ''; } if (isset($image_data['url_hover_remove']) && $image_data['url_hover_remove']) { $image_data['url_hover_remove'] = ''; $image_data['url_hover'] = ''; } if (!isset($image_data['url_server']) || isset($image_data['url_server']) && empty($image_data['url_server'])) { if (isset($image_data['url']) && $image_data['url']) { $ext = JFile::getExt($image_data['url']); $path_copy = str_replace('.' . $ext, '_o.' . $ext, $image_data['url']); if (JFile::exists(JPATH_ROOT . DIRECTORY_SEPARATOR . $path_copy)) { $image_data['url_server'] = $path_copy; $image_data['url'] = ''; } } } if (!isset($image_data['url_hover_server']) || isset($image_data['url_hover_server']) && empty($image_data['url_hover_server'])) { if (isset($image_data['url_hover']) && $image_data['url_hover']) { $ext = JFile::getExt($image_data['url_hover']); $path_copy = str_replace('.' . $ext, '_o.' . $ext, $image_data['url_hover']); if (JFile::exists(JPATH_ROOT . DIRECTORY_SEPARATOR . $path_copy)) { $image_data['url_hover_server'] = $path_copy; $image_data['url_hover'] = ''; } } } } // Remove image and image hover with resized if ($image_size = $params->get('image_size', array())) { $image_size = $this->prepareImageSize($image_size); if (is_array($image_size) && count($image_size)) { foreach ($image_size as $_size) { $size = json_decode($_size); // Delete old image files if (isset($image_data['url_remove']) && $image_data['url_remove'] && $media && isset($media->url) && !empty($media->url)) { $image_url = $media->url; $image_url = str_replace('.' . JFile::getExt($image_url), '_' . $size->image_name_prefix . '.' . JFile::getExt($image_url), $image_url); JFile::delete(JPATH_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $image_url)); } // Delete old image hover files if (isset($image_data['url_hover_remove']) && $image_data['url_hover_remove'] && $media && isset($media->url_hover) && !empty($media->url_hover)) { $image_url = $media->url_hover; $image_url = str_replace('.' . JFile::getExt($image_url), '_' . $size->image_name_prefix . '.' . JFile::getExt($image_url), $image_url); JFile::delete(JPATH_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $image_url)); } } } } // Remove Image file when tick to remove file box if (isset($image_data['url_remove']) && $image_data['url_remove']) { // Before upload image to file must delete original file if ($media && isset($media->url) && !empty($media->url)) { $image_url = $media->url; $image_url = str_replace('.' . JFile::getExt($image_url), '_o' . '.' . JFile::getExt($image_url), $image_url); if (JFile::delete(JPATH_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $image_url))) { $image_data['url'] = ''; unset($image_data['url_remove']); } } } else { unset($image_data['url']); } // Remove Image hover file when tick to remove file box if (isset($image_data['url_hover_remove']) && $image_data['url_hover_remove']) { // Before upload image to file must delete original file if ($media && isset($media->url_hover) && !empty($media->url_hover)) { $image_url = $media->url_hover; $image_url = str_replace('.' . JFile::getExt($image_url), '_o' . '.' . JFile::getExt($image_url), $image_url); if (JFile::delete(JPATH_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $image_url))) { $image_data['url_hover'] = ''; unset($image_data['url_hover_remove']); } } } else { unset($image_data['url_hover']); } $images = array(); $images_hover = array(); $imageObj = new JImage(); // Upload image or image hover if ($files = $input->files->get('jform', array(), 'array')) { if (isset($files['media']) && isset($files['media']['image'])) { $files = $files['media']['image']; // Get image from form if (isset($files['url_client']['name']) && !empty($files['url_client']['name'])) { $images = $files['url_client']; } // Get image hover data from form if (isset($files['url_hover_client']['name']) && !empty($files['url_hover_client']['name'])) { $images_hover = $files['url_hover_client']; } } } $path = ''; $path_hover = ''; jimport('joomla.filesystem.file'); $imageType = null; $imageMimeType = null; $imageSize = null; $image_hoverType = null; $image_hoverMimeType = null; $image_hoverSize = null; // Create original image with new name (upload from client) if (count($images) && !empty($images['tmp_name'])) { // Get image file type $imageType = JFile::getExt($images['name']); $imageType = strtolower($imageType); // Get image's mime type $imageMimeType = $images['type']; // Get image's size $imageSize = $images['size']; $path = COM_TZ_PORTFOLIO_PLUS_MEDIA_ARTICLE_ROOT . DIRECTORY_SEPARATOR; $path .= $data->alias . '-' . $data->id . '_o'; $path .= '.' . JFile::getExt($images['name']); if ($input->getCmd('task') == 'save2copy' && $input->getInt('id')) { $image_data['url_server'] = null; } } elseif (isset($image_data['url_server']) && !empty($image_data['url_server'])) { // Create original image with new name (upload from server) // Get image file type $imageType = JFile::getExt($image_data['url_server']); $imageType = strtolower($imageType); // Get image's mime type $imageObj->loadFile(JPATH_ROOT . DIRECTORY_SEPARATOR . $image_data['url_server']); $imageMimeType = $imageObj->getImageFileProperties($imageObj->getPath()); $imageMimeType = $imageMimeType->mime; // Get image's size $imageSize = $imageMimeType->filesize; $path = COM_TZ_PORTFOLIO_PLUS_MEDIA_ARTICLE_ROOT . DIRECTORY_SEPARATOR; $path .= $data->alias . '-' . $data->id . '_o'; $path .= '.' . JFile::getExt($image_data['url_server']); } // Create original image hover with new name (upload from client) if (count($images_hover) && !empty($images_hover['tmp_name'])) { // Get image hover file type $image_hoverType = JFile::getExt($images_hover['name']); $image_hoverType = strtolower($image_hoverType); // Get image hover's mime type $image_hoverMimeType = $images_hover['type']; // Get image's size $image_hoverSize = $images_hover['size']; $path_hover = COM_TZ_PORTFOLIO_PLUS_MEDIA_ARTICLE_ROOT . DIRECTORY_SEPARATOR; $path_hover .= $data->alias . '-' . $data->id . '-h_o'; $path_hover .= '.' . JFile::getExt($images_hover['name']); if ($input->getCmd('task') == 'save2copy' && $input->getInt('id')) { $image_data['url_hover_server'] = null; } } elseif (isset($image_data['url_hover_server']) && !empty($image_data['url_hover_server'])) { // Create original image with new name (upload from server) // Get image hover file type $image_hoverType = JFile::getExt($image_data['url_hover_server']); $image_hoverType = strtolower($image_hoverType); // Get image hover's mime type $imageObj->loadFile(JPATH_ROOT . DIRECTORY_SEPARATOR . $image_data['url_hover_server']); $image_hoverMimeType = $imageObj->getImageFileProperties($imageObj->getPath()); $image_hoverMimeType = $image_hoverMimeType->mime; // Get image hover's size $image_hoverSize = $image_hoverMimeType->filesize; $path_hover = COM_TZ_PORTFOLIO_PLUS_MEDIA_ARTICLE_ROOT . DIRECTORY_SEPARATOR; $path_hover .= $data->alias . '-' . $data->id . '-h_o'; $path_hover .= '.' . JFile::getExt($image_data['url_hover_server']); } // Upload original image if ($path && !empty($path)) { //-- Check image information --// // Check MIME Type if (!in_array($imageMimeType, $mime_types)) { $app->enqueueMessage(JText::_('PLG_MEDIATYPE_IMAGE_ERROR_WARNINVALID_MIME'), 'notice'); return false; } // Check file type if (!in_array($imageType, $file_types)) { $app->enqueueMessage(JText::_('PLG_MEDIATYPE_IMAGE_ERROR_WARNFILETYPE'), 'notice'); return false; } // Check file size if ($imageSize > $file_sizes) { $app->enqueueMessage(JText::_('PLG_MEDIATYPE_IMAGE_ERROR_WARNFILETOOLARGE'), 'notice'); return false; } //-- End check image information --// // Before upload image to file must delete original file if ($media && isset($media->url) && !empty($media->url)) { $image_url = $media->url; $image_url = str_replace('.' . JFile::getExt($image_url), '_o' . '.' . JFile::getExt($image_url), $image_url); JFile::delete(JPATH_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $image_url)); } if (isset($images['tmp_name']) && !empty($images['tmp_name']) && !JFile::upload($images['tmp_name'], $path)) { $path = ''; } elseif (isset($image_data['url_server']) && !empty($image_data['url_server']) && !JFile::copy(JPATH_ROOT . DIRECTORY_SEPARATOR . $image_data['url_server'], $path)) { $path = ''; } } // Upload original image hover if ($path_hover && !empty($path_hover)) { //-- Check image information --// // Check MIME Type if (!in_array($image_hoverMimeType, $mime_types)) { $app->enqueueMessage(JText::_('PLG_MEDIATYPE_IMAGE_ERROR_WARNINVALID_MIME'), 'notice'); return false; } // Check file type if (!in_array($image_hoverType, $file_types)) { $app->enqueueMessage(JText::_('PLG_MEDIATYPE_IMAGE_ERROR_WARNFILETYPE'), 'notice'); return false; } // Check file size if ($image_hoverSize > $file_sizes) { $app->enqueueMessage(JText::_('PLG_MEDIATYPE_IMAGE_ERROR_WARNFILETOOLARGE'), 'notice'); return false; } //-- End check image information --// // Before upload image hover file to file must delete original file if ($media && isset($media->url_hover) && !empty($media->url_hover)) { $image_url = $media->url_hover; $image_url = str_replace('.' . JFile::getExt($image_url), '_o' . '.' . JFile::getExt($image_url), $image_url); JFile::delete(JPATH_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $image_url)); } if (isset($images_hover['tmp_name']) && !empty($images_hover['tmp_name']) && !JFile::upload($images_hover['tmp_name'], $path_hover)) { $path_hover = ''; } elseif (isset($image_data['url_hover_server']) && !empty($image_data['url_hover_server']) && !JFile::copy(JPATH_ROOT . DIRECTORY_SEPARATOR . $image_data['url_hover_server'], $path_hover)) { $path_hover = ''; } } // Upload image and image hover with resize if ($image_size = $params->get('image_size')) { $image_size = $this->prepareImageSize($image_size); $image = null; $image_hover = null; if (is_array($image_size) && count($image_size)) { foreach ($image_size as $_size) { $size = json_decode($_size); // Upload image with resize if ($path) { // Create new ratio from new with of image size param $imageObj->loadFile($path); $imgProperties = $imageObj->getImageFileProperties($imageObj->getPath()); $newH = $imgProperties->height * $size->width / $imgProperties->width; $newImage = $imageObj->resize($size->width, $newH); $newPath = COM_TZ_PORTFOLIO_PLUS_MEDIA_ARTICLE_ROOT . DIRECTORY_SEPARATOR . $data->alias . '-' . $data->id . '_' . $size->image_name_prefix . '.' . JFile::getExt($path); // Before generate image to file must delete old files if ($media && isset($media->url) && !empty($media->url)) { $image_url = $media->url; $image_url = str_replace('.' . JFile::getExt($image_url), '_' . $size->image_name_prefix . '.' . JFile::getExt($image_url), $image_url); JFile::delete(JPATH_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $image_url)); } // Generate image to file $newImage->toFile($newPath, $imgProperties->type); } // Upload image hover with resize if ($path_hover) { // Create new ratio from new with of image size param $imageObj->loadFile($path_hover); $imgHoverProperties = $imageObj->getImageFileProperties($imageObj->getPath()); $newH = $imgHoverProperties->height * $size->width / $imgHoverProperties->width; $newHImage = $imageObj->resize($size->width, $newH); $newHPath = COM_TZ_PORTFOLIO_PLUS_MEDIA_ARTICLE_ROOT . DIRECTORY_SEPARATOR . $data->alias . '-' . $data->id . '-h_' . $size->image_name_prefix . '.' . JFile::getExt($path_hover); // Before generate image hover to file must delete old files if ($media && isset($media->url_hover) && !empty($media->url_hover)) { $image_url_hover = $media->url_hover; $image_url_hover = str_replace('.' . JFile::getExt($image_url_hover), '_' . $size->image_name_prefix . '.' . JFile::getExt($image_url_hover), $image_url_hover); JFile::delete(JPATH_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $image_url_hover)); } // Generate image to file $newHImage->toFile($newHPath, $imgHoverProperties->type); } } } } if ($path && !empty($path)) { $image_data['url'] = COM_TZ_PORTFOLIO_PLUS_MEDIA_ARTICLE_BASE . '/' . $data->alias . '-' . $data->id . '.' . JFile::getExt($path); } if ($path_hover && !empty($path_hover)) { $image_data['url_hover'] = COM_TZ_PORTFOLIO_PLUS_MEDIA_ARTICLE_BASE . '/' . $data->alias . '-' . $data->id . '-h.' . JFile::getExt($path_hover); } unset($image_data['url_server']); unset($image_data['url_hover_server']); $this->__save($data, $image_data); // } }
/** * Method to load a file into the JImage object as the resource. * * @param string $path The filesystem path to load as an image. * * @return void * * @since 11.3 * @throws InvalidArgumentException * @throws RuntimeException */ public function loadFile($path) { // Destroy the current image handle if it exists $this->destroy(); return parent::loadFile($path); }
/** * Store the file in a folder of the extension. * * @param array $image * @param bool $resizeImage * * @throws \RuntimeException * @throws \Exception * @throws \InvalidArgumentException * * @return array */ public function uploadImage($image, $resizeImage = false) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $uploadedFile = ArrayHelper::getValue($image, 'tmp_name'); $uploadedName = ArrayHelper::getValue($image, 'name'); $errorCode = ArrayHelper::getValue($image, 'error'); $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ $filesystemHelper = new Prism\Filesystem\Helper($params); $mediaFolder = $filesystemHelper->getMediaFolder(); $destinationFolder = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $mediaFolder); $temporaryFolder = $app->get('tmp_path'); // Joomla! media extension parameters $mediaParams = JComponentHelper::getParams('com_media'); /** @var $mediaParams Joomla\Registry\Registry */ $file = new Prism\File\File(); // Prepare size validator. $KB = 1024 * 1024; $fileSize = (int) $app->input->server->get('CONTENT_LENGTH'); $uploadMaxSize = $mediaParams->get('upload_maxsize') * $KB; // Prepare file validators. $sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize); $serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE)); $imageValidator = new Prism\File\Validator\Image($uploadedFile, $uploadedName); // Get allowed mime types from media manager options $mimeTypes = explode(',', $mediaParams->get('upload_mime')); $imageValidator->setMimeTypes($mimeTypes); // Get allowed image extensions from media manager options $imageExtensions = explode(',', $mediaParams->get('image_extensions')); $imageValidator->setImageExtensions($imageExtensions); $file->addValidator($sizeValidator)->addValidator($serverValidator)->addValidator($imageValidator); // Validate the file if (!$file->isValid()) { throw new RuntimeException($file->getError()); } // Generate temporary file name $ext = strtolower(JFile::makeSafe(JFile::getExt($image['name']))); $generatedName = Prism\Utilities\StringHelper::generateRandomString(); $temporaryFile = $generatedName . '_reward.' . $ext; $temporaryDestination = JPath::clean($temporaryFolder . DIRECTORY_SEPARATOR . $temporaryFile); // Prepare uploader object. $uploader = new Prism\File\Uploader\Local($uploadedFile); $uploader->setDestination($temporaryDestination); // Upload temporary file $file->setUploader($uploader); $file->upload(); $temporaryFile = $file->getFile(); if (!is_file($temporaryFile)) { throw new Exception('COM_GAMIFICATION_ERROR_FILE_CANT_BE_UPLOADED'); } // Resize image $image = new JImage(); $image->loadFile($temporaryFile); if (!$image->isLoaded()) { throw new Exception(JText::sprintf('COM_GAMIFICATION_ERROR_FILE_NOT_FOUND', $temporaryDestination)); } $imageName = $generatedName . '_image.png'; $smallName = $generatedName . '_small.png'; $squareName = $generatedName . '_square.png'; $imageFile = $destinationFolder . DIRECTORY_SEPARATOR . $imageName; $smallFile = $destinationFolder . DIRECTORY_SEPARATOR . $smallName; $squareFile = $destinationFolder . DIRECTORY_SEPARATOR . $squareName; $scaleOption = $params->get('image_resizing_scale', JImage::SCALE_INSIDE); // Create main image if (!$resizeImage) { $image->toFile($imageFile, IMAGETYPE_PNG); } else { $width = $params->get('image_width', 200); $height = $params->get('image_height', 200); $image->resize($width, $height, false, $scaleOption); $image->toFile($imageFile, IMAGETYPE_PNG); } // Create small image $width = $params->get('image_small_width', 100); $height = $params->get('image_small_height', 100); $image->resize($width, $height, false, $scaleOption); $image->toFile($smallFile, IMAGETYPE_PNG); // Create square image $width = $params->get('image_square_width', 50); $height = $params->get('image_square_height', 50); $image->resize($width, $height, false, $scaleOption); $image->toFile($squareFile, IMAGETYPE_PNG); $names = array('image' => $imageName, 'image_small' => $smallName, 'image_square' => $squareName); // Remove the temporary file. if (JFile::exists($temporaryFile)) { JFile::delete($temporaryFile); } return $names; }
/** * Resize the temporary file to new one. * * <code> * $image = $this->input->files->get('media', array(), 'array'); * $rootFolder = "/root/joomla/tmp"; * * $resizeOptions = array( * 'width' => $options['thumb_width'], * 'height' => $options['thumb_height'], * 'scale' => $options['thumb_scale'] * ); * * $file = new Prism\File\Image($image, $rootFolder); * * $file->upload(); * $fileData = $file->resize($resize); * </code> * * @param array $options * @param bool $replace Replace the original file with the new one. * @param string $prefix Filename prefix. * * @throws \RuntimeException * * @return array */ public function resize(array $options, $replace = false, $prefix = '') { if (!$this->file) { throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND_S', $this->file)); } // Resize image. $image = new \JImage(); $image->loadFile($this->file); if (!$image->isLoaded()) { throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND_S', $this->file)); } // Resize to general size. $width = ArrayHelper::getValue($options, 'width', 640); $width = $width < 50 ? 50 : $width; $height = ArrayHelper::getValue($options, 'height', 480); $height = $height < 50 ? 50 : $height; $scale = ArrayHelper::getValue($options, 'scale', \JImage::SCALE_INSIDE); $image->resize($width, $height, false, $scale); // Generate new name. $generatedName = StringHelper::generateRandomString($this->options->get('filename_length', 16)) . '.png'; if (is_string($prefix) and $prefix !== '') { $generatedName = $prefix . $generatedName; } $file = \JPath::clean($this->rootFolder . '/' . $generatedName); // Store to file. $image->toFile($file, IMAGETYPE_PNG); if ($replace) { \JFile::delete($this->file); $this->file = $file; } // Prepare meta data about the file. $fileData = array('filename' => $generatedName, 'filepath' => $file, 'type' => 'image'); $fileData = array_merge($fileData, $this->prepareImageProperties($this->file)); return $fileData; }
/** * Crop the image and generates smaller ones. * * @param string $file * @param array $options * @param Joomla\Registry\Registry $params * * @throws Exception * * @return array */ public function cropImage($file, $options, $params) { // Resize image $image = new JImage(); $image->loadFile($file); if (!$image->isLoaded()) { throw new Exception(JText::sprintf('COM_SOCIALCOMMUNITY_ERROR_FILE_NOT_FOUND', $file)); } $destinationFolder = Joomla\Utilities\ArrayHelper::getValue($options, 'destination'); // Generate temporary file name $generatedName = Prism\Utilities\StringHelper::generateRandomString(24); $profileName = $generatedName . '_profile.png'; $smallName = $generatedName . '_small.png'; $squareName = $generatedName . '_square.png'; $iconName = $generatedName . '_icon.png'; $imageFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $profileName); $smallFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $smallName); $squareFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $squareName); $iconFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $iconName); // Create profile image. $width = Joomla\Utilities\ArrayHelper::getValue($options, 'width', 200); $width = $width < 25 ? 50 : $width; $height = Joomla\Utilities\ArrayHelper::getValue($options, 'height', 200); $height = $height < 25 ? 50 : $height; $left = Joomla\Utilities\ArrayHelper::getValue($options, 'x', 0); $top = Joomla\Utilities\ArrayHelper::getValue($options, 'y', 0); $image->crop($width, $height, $left, $top, false); // Resize to general size. $width = $params->get('image_width', 200); $width = $width < 25 ? 50 : $width; $height = $params->get('image_height', 200); $height = $height < 25 ? 50 : $height; $image->resize($width, $height, false); // Store to file. $image->toFile($imageFile, IMAGETYPE_PNG); // Create small image. $width = $params->get('image_small_width', 100); $height = $params->get('image_small_height', 100); $image->resize($width, $height, false); $image->toFile($smallFile, IMAGETYPE_PNG); // Create square image. $width = $params->get('image_square_width', 50); $height = $params->get('image_square_height', 50); $image->resize($width, $height, false); $image->toFile($squareFile, IMAGETYPE_PNG); // Create icon image. $width = $params->get('image_icon_width', 25); $height = $params->get('image_icon_height', 25); $image->resize($width, $height, false); $image->toFile($iconFile, IMAGETYPE_PNG); $names = array('image_profile' => $profileName, 'image_small' => $smallName, 'image_square' => $squareName, 'image_icon' => $iconName); // Remove the temporary file. if (JFile::exists($file)) { JFile::delete($file); } return $names; }
/** * Crop the image and generates smaller ones. * * @param string $file * @param array $options * * @throws Exception * * @return array */ public function cropImage($file, $options) { // Resize image $image = new JImage(); $image->loadFile($file); if (!$image->isLoaded()) { throw new Exception(JText::sprintf('COM_CROWDFUNDING_ERROR_FILE_NOT_FOUND', $file)); } $destinationFolder = Joomla\Utilities\ArrayHelper::getValue($options, "destination"); // Generate temporary file name $generatedName = new Prism\String(); $generatedName->generateRandomString(32); $imageName = $generatedName . "_image.png"; $smallName = $generatedName . "_small.png"; $squareName = $generatedName . "_square.png"; $imageFile = $destinationFolder . DIRECTORY_SEPARATOR . $imageName; $smallFile = $destinationFolder . DIRECTORY_SEPARATOR . $smallName; $squareFile = $destinationFolder . DIRECTORY_SEPARATOR . $squareName; // Create main image $width = Joomla\Utilities\ArrayHelper::getValue($options, "width", 200); $width = $width < 25 ? 50 : $width; $height = Joomla\Utilities\ArrayHelper::getValue($options, "height", 200); $height = $height < 25 ? 50 : $height; $left = Joomla\Utilities\ArrayHelper::getValue($options, "x", 0); $top = Joomla\Utilities\ArrayHelper::getValue($options, "y", 0); $image->crop($width, $height, $left, $top, false); // Resize to general size. $width = Joomla\Utilities\ArrayHelper::getValue($options, "resize_width", 200); $width = $width < 25 ? 50 : $width; $height = Joomla\Utilities\ArrayHelper::getValue($options, "resize_height", 200); $height = $height < 25 ? 50 : $height; $image->resize($width, $height, false); // Store to file. $image->toFile($imageFile, IMAGETYPE_PNG); // Load parameters. $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ // Create small image $width = $params->get("image_small_width", 100); $height = $params->get("image_small_height", 100); $image->resize($width, $height, false); $image->toFile($smallFile, IMAGETYPE_PNG); // Create square image $width = $params->get("image_square_width", 50); $height = $params->get("image_square_height", 50); $image->resize($width, $height, false); $image->toFile($squareFile, IMAGETYPE_PNG); $names = array("image" => $imageName, "image_small" => $smallName, "image_square" => $squareName); // Remove the temporary file. if (is_file($file)) { JFile::delete($file); } return $names; }
function uploadImages($file) { if ($file) { $maxSize = 2 * 1024 * 1024; $arr = array('image/jpeg', 'image/jpg', 'image/bmp', 'image/gif', 'image/png', 'image/ico'); // Create folder $tzFolder = 'tz_pinboard'; $tzUserFolder = 'users'; $tzFolderPath = JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $tzFolder; $tzUserFolderPath = $tzFolderPath . DIRECTORY_SEPARATOR . $tzUserFolder; if (!JFolder::exists($tzFolderPath)) { JFolder::create($tzFolderPath); if (!JFile::exists($tzFolderPath . DIRECTORY_SEPARATOR . 'index.html')) { JFile::write($tzFolderPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>')); } } if (JFolder::exists($tzFolderPath)) { if (!JFolder::exists($tzUserFolderPath)) { JFolder::create($tzUserFolderPath); if (!JFile::exists($tzUserFolderPath . DIRECTORY_SEPARATOR . 'index.html')) { JFile::write($tzUserFolderPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>')); } } } if (is_array($file)) { foreach ($file as $key => $val) { if (is_array($val)) { foreach ($val as $key2 => $val2) { $file[$key] = $val2; } } } //Upload image if (!in_array($file['type'], $arr)) { $this->setError(JText::_('Invalid file type')); return false; } if ($file['size'] > $maxSize) { $this->setError(JText::_('This file size too large')); return false; } $desFileName = 'user_' . time() . uniqid() . '.' . JFile::getExt($file['name']); $desPath = $tzUserFolderPath . DIRECTORY_SEPARATOR . $desFileName; if (JFile::exists($file['tmp_name'])) { if (!JFile::copy($file['tmp_name'], $desPath)) { $this->setError(JText::_('Can not upload file')); return false; } $image = new JImage(); $image->loadFile($desPath); $params = JComponentHelper::getParams('com_tz_pinboard'); if ($params->get('tz_user_image_width', 100)) { $width = $params->get('tz_user_image_width', 100); } $height = ceil($image->getHeight() * $width / $image->getWidth()); $image = $image->resize($width, $height); $type = $this->_getImageType($file['name']); $image->toFile($desPath, $type); return 'media/' . $tzFolder . '/' . $tzUserFolder . '/' . $desFileName; } } else { require_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'HTTPFetcher.php'; require_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'readfile.php'; $image = new Services_Yadis_PlainHTTPFetcher(); $image = $image->get($file); if (!in_array($image->headers['Content-Type'], $arr)) { $this->setError(JText::_('Invalid file')); return false; } if ($image->headers['Content-Length'] > $maxSize) { $this->setError(JText::_('This file size too large')); return false; } $desFileName = 'user_' . time() . uniqid() . '.' . str_replace('image/', '', $image->headers['Content-Type']); $desPath = $tzUserFolderPath . DIRECTORY_SEPARATOR . $desFileName; if (JFolder::exists($tzFolderPath)) { if (!JFile::write($desPath, $image->body)) { $this->setError(JText::_('Can not upload file')); return false; } return 'media/' . $tzFolder . '/' . $tzUserFolder . '/' . $desFileName; } } } return true; }
/** * Upload an image * * @param array $image Array with information about uploaded file. * * @throws RuntimeException * @return array */ public function uploadImage($image) { $app = JFactory::getApplication(); /** @var $app JApplicationAdministrator */ $uploadedFile = Joomla\Utilities\ArrayHelper::getValue($image, 'tmp_name'); $uploadedName = Joomla\Utilities\ArrayHelper::getValue($image, 'name'); $errorCode = Joomla\Utilities\ArrayHelper::getValue($image, 'error'); $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ $temporaryFolder = JPath::clean($app->get('tmp_path')); // Joomla! media extension parameters /** @var $mediaParams Joomla\Registry\Registry */ $mediaParams = JComponentHelper::getParams('com_media'); $file = new Prism\File\File(); // Prepare size validator. $KB = 1024 * 1024; $fileSize = (int) $app->input->server->get('CONTENT_LENGTH'); $uploadMaxSize = $mediaParams->get('upload_maxsize') * $KB; // Prepare file size validator $sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize); // Prepare server validator. $serverValidator = new Prism\File\Validator\Server($errorCode); // Prepare image validator. $imageValidator = new Prism\File\Validator\Image($uploadedFile, $uploadedName); // Get allowed mime types from media manager options $mimeTypes = explode(',', $mediaParams->get('upload_mime')); $imageValidator->setMimeTypes($mimeTypes); // Get allowed image extensions from media manager options $imageExtensions = explode(',', $mediaParams->get('image_extensions')); $imageValidator->setImageExtensions($imageExtensions); $file->addValidator($sizeValidator)->addValidator($imageValidator)->addValidator($serverValidator); // Validate the file if (!$file->isValid()) { throw new RuntimeException($file->getError()); } // Generate temporary file name $ext = JFile::makeSafe(JFile::getExt($image['name'])); $generatedName = Prism\Utilities\StringHelper::generateRandomString(16); $originalFile = JPath::clean($temporaryFolder . DIRECTORY_SEPARATOR . $generatedName . '.' . $ext); if (!JFile::upload($uploadedFile, $originalFile)) { throw new \RuntimeException(\JText::_('COM_SOCIALCOMMUNITY_ERROR_FILE_CANT_BE_UPLOADED')); } // Generate file names for the image files. $generatedName = Prism\Utilities\StringHelper::generateRandomString(16); $imageName = $generatedName . '_image.png'; $smallName = $generatedName . '_small.png'; $squareName = $generatedName . '_square.png'; $iconName = $generatedName . '_icon.png'; // Resize image $image = new JImage(); $image->loadFile($originalFile); if (!$image->isLoaded()) { throw new RuntimeException(JText::sprintf('COM_SOCIALCOMMUNITY_ERROR_FILE_NOT_FOUND', $originalFile)); } $imageFile = JPath::clean($temporaryFolder . DIRECTORY_SEPARATOR . $imageName); $smallFile = JPath::clean($temporaryFolder . DIRECTORY_SEPARATOR . $smallName); $squareFile = JPath::clean($temporaryFolder . DIRECTORY_SEPARATOR . $squareName); $iconFile = JPath::clean($temporaryFolder . DIRECTORY_SEPARATOR . $iconName); // Create profile picture $width = $params->get('image_width', 200); $height = $params->get('image_height', 200); $image->resize($width, $height, false); $image->toFile($imageFile, IMAGETYPE_PNG); // Create small profile picture $width = $params->get('small_width', 100); $height = $params->get('small_height', 100); $image->resize($width, $height, false); $image->toFile($smallFile, IMAGETYPE_PNG); // Create square picture $width = $params->get('square_width', 50); $height = $params->get('square_height', 50); $image->resize($width, $height, false); $image->toFile($squareFile, IMAGETYPE_PNG); // Create icon picture $width = $params->get('icon_width', 24); $height = $params->get('icon_height', 24); $image->resize($width, $height, false); $image->toFile($iconFile, IMAGETYPE_PNG); // Remove the temporary file if (JFile::exists($originalFile)) { JFile::delete($originalFile); } return $names = array('image' => $imageName, 'image_small' => $smallName, 'image_icon' => $iconName, 'image_square' => $squareName); }
/** * Upload an image * * @param array $image * @param string $destination * * @throws Exception * @return array */ public function uploadImage($image, $destination) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $uploadedFile = Joomla\Utilities\ArrayHelper::getValue($image, 'tmp_name'); $uploadedName = Joomla\Utilities\ArrayHelper::getValue($image, 'name'); $errorCode = Joomla\Utilities\ArrayHelper::getValue($image, 'error'); // Load parameters. $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ $tmpFolder = $app->get('tmp_path'); // Joomla! media extension parameters $mediaParams = JComponentHelper::getParams('com_media'); /** @var $mediaParams Joomla\Registry\Registry */ $file = new Prism\File\File(); // Prepare size validator. $KB = 1024 * 1024; $fileSize = (int) $app->input->server->get('CONTENT_LENGTH'); $uploadMaxSize = $mediaParams->get('upload_maxsize') * $KB; $sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize); // Prepare server validator. $serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE)); // Prepare image validator. $imageValidator = new Prism\File\Validator\Image($uploadedFile, $uploadedName); // Get allowed mime types from media manager options $mimeTypes = explode(',', $mediaParams->get('upload_mime')); $imageValidator->setMimeTypes($mimeTypes); // Get allowed image extensions from media manager options $imageExtensions = explode(',', $mediaParams->get('image_extensions')); $imageValidator->setImageExtensions($imageExtensions); $file->addValidator($sizeValidator)->addValidator($imageValidator)->addValidator($serverValidator); // Validate the file if (!$file->isValid()) { throw new RuntimeException($file->getError()); } // Generate temporary file name $ext = JString::strtolower(JFile::makeSafe(JFile::getExt($image['name']))); $generatedName = Prism\Utilities\StringHelper::generateRandomString(32); $tmpDestFile = JPath::clean($tmpFolder . DIRECTORY_SEPARATOR . $generatedName . '.' . $ext); // Prepare uploader object. $uploader = new Prism\File\Uploader\Local($uploadedFile); $uploader->setDestination($tmpDestFile); // Upload temporary file $file->setUploader($uploader); $file->upload(); // Get file $tmpDestFile = $file->getFile(); if (!is_file($tmpDestFile)) { throw new Exception('COM_CROWDFUNDING_ERROR_FILE_CANT_BE_UPLOADED'); } // Resize image $image = new JImage(); $image->loadFile($tmpDestFile); if (!$image->isLoaded()) { throw new Exception(JText::sprintf('COM_CROWDFUNDING_ERROR_FILE_NOT_FOUND', $tmpDestFile)); } $imageName = $generatedName . '_pimage.png'; $imageFile = $destination . DIRECTORY_SEPARATOR . $imageName; // Get the scale method. $scaleMethod = $params->get('image_resizing_scale', JImage::SCALE_INSIDE); // Create main image $width = $params->get('pitch_image_width', 600); $height = $params->get('pitch_image_height', 400); $image->resize($width, $height, false, $scaleMethod); $image->toFile($imageFile, IMAGETYPE_PNG); // Remove the temporary file. if (is_file($tmpDestFile)) { JFile::delete($tmpDestFile); } return $imageName; }