AAAAhome/academiac/www/administrator/components/com_virtuemart/helpers/image.php000060400000015513151372165200023554 0ustar00file_url; $file_name = $this->uploadFile($this->file_url_folder); if($file_name){ if($file_name!=$oldFileUrl && !empty($this->filename)){ $this->deleteFile($oldFileUrl); } $this->file_url = $this->file_url_folder.$file_name; $this->filename = $file_name; $oldFileUrlThumb = $this->file_url_thumb; $this->file_url_thumb = $this->createThumb(); if($this->file_url_thumb!=$oldFileUrlThumb){ $this->deleteFile($oldFileUrlThumb); } } } //creating the thumbnail image else if( $data['media_action'] == 'create_thumb' ){ $this->file_url_thumb = $this->createThumb(); } if(empty($this->file_title) && !empty($file_name)) $this->file_title = $file_name; return $data; } function displayMediaFull($imageArgs='',$lightbox=true,$effect ="class='modal'",$description = true ){ if(!$this->file_is_forSale){ // Remote image URL if( substr( $this->file_url, 0, 4) == "http" ) { $file_url = $this->file_url; $file_alt = $this->file_title; } else { $rel_path = str_replace('/',DS,$this->file_url_folder); $fullSizeFilenamePath = JPATH_ROOT.DS.$rel_path.$this->file_name.'.'.$this->file_extension; if (!file_exists($fullSizeFilenamePath)) { $file_url = $this->theme_url.'assets/images/vmgeneral/'.VmConfig::get('no_image_found'); $file_alt = JText::_('COM_VIRTUEMART_NO_IMAGE_FOUND').' '.$this->file_description; } else { $file_url = $this->file_url; $file_alt = $this->file_meta; } } $postText = false; if($description) $postText = $this->file_description; return $this->displayIt($file_url, $file_alt, $imageArgs,$lightbox,$effect,$postText); } else { //Media which should be sold, show them only as thumb (works as preview) return $this->displayMediaThumb('id="vm_display_image"',false); } } public function createThumbFileUrl(){ $file_name = $this->createThumbName(); if(empty($this->file_name_thumb)) { vmdebug('createThumbFileUrl empty file_name_thumb ',$this); return false; } $file_url_thumb = $this->file_url_folder.'resized/'.$this->file_name_thumb.'.'.$this->file_extension; return $file_url_thumb; } /** * a small function that ensures that we always build the thumbnail name with the same method */ public function createThumbName($width=0,$height=0){ if(empty($this->file_name)) return false; if(empty($width)) $width = VmConfig::get('img_width', 90); if(empty($height)) $height = VmConfig::get('img_height', 90); $this->file_name_thumb = $this->file_name.'_'.$width.'x'.$height; return $this->file_name_thumb; } /** * This function actually creates the thumb * and when it is instanciated with one of the getImage function automatically updates the db * * @author Max Milbers * @param boolean $save Execute update function * @return name of the thumbnail */ public function createThumb($width=0,$height=0) { if(empty($this->file_url_folder)){ vmError('Couldnt create thumb, no directory given. Activate vmdebug to understand which database entry is creating this error'); vmdebug('createThumb, no directory given',$this); return FALSE; } if(empty($this->file_name)){ vmError('Couldnt create thumb, no name given. Activate vmdebug to understand which database entry is creating this error'); vmdebug('createThumb, no name given',$this); return false; } $synchronise = JRequest::getString('synchronise',false); if(!VmConfig::get('img_resize_enable') || $synchronise) return; //now lets create the thumbnail, saving is done in this function if(empty($width)) $width = VmConfig::get('img_width', 90); if(empty($height)) $height = VmConfig::get('img_height', 90); // Don't allow sizes beyond 2000 pixels //I dont think that this is good, should be config // $width = min($width, 2000); // $height = min($height, 2000); $maxsize = false; $bgred = 255; $bggreen = 255; $bgblue = 255; $root = ''; $this->file_name_thumb = $this->createThumbName($width,$height); if($this->file_is_forSale==0){ $rel_path = str_replace('/',DS,$this->file_url_folder); $fullSizeFilenamePath = JPATH_ROOT.DS.$rel_path.$this->file_name.'.'.$this->file_extension; } else { $fullSizeFilenamePath = $this->file_url_folder.$this->file_name.'.'.$this->file_extension; } $file_path_thumb = str_replace('/',DS,$this->file_url_folder_thumb); $resizedFilenamePath = JPATH_ROOT.DS.$file_path_thumb.$this->file_name_thumb.'.'.$this->file_extension; $this->checkPathCreateFolders($file_path_thumb); if (file_exists($fullSizeFilenamePath)) { if (!class_exists('Img2Thumb')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'img2thumb.php'); $createdImage = new Img2Thumb($fullSizeFilenamePath, (int)$width, (int)$height, $resizedFilenamePath, $maxsize, $bgred, $bggreen, $bgblue); if($createdImage){ return $this->file_url_folder_thumb.$this->file_name_thumb.'.'.$this->file_extension; } else { return 0; } } else { vmError('Couldnt create thumb, file not found '.$fullSizeFilenamePath); return 0; } } public function checkPathCreateFolders($path){ $elements = explode(DS,$path); $examine = JPATH_ROOT; foreach($elements as $piece){ $examine = $examine.DS.$piece; if(!JFolder::exists($examine)){ JFolder::create($examine); vmInfo('create folder for resized image '.$examine); } } } /** * Display an image icon for the given image and create a link to the given link. * * @param string $link Link to use in the href tag * @param string $image Name of the image file to display * @param string $text Text to use for the image alt text and to display under the image. */ static public function displayImageButton($link, $imageclass, $text, $mainclass = 'vmicon48', $extra="") { $button = ''; $button .= ''; $button .= '
' . $text.'
'; echo $button; } } home/academiac/www/libraries/joomla/image/image.php000064400000047117151372706330016342 0ustar00handle = &$source; } elseif (!empty($source) && is_string($source)) { // If the source input is not empty, assume it is a path and populate the image handle. $this->loadFile($source); } } /** * Method to return a properties object for an image given a filesystem path. The * result object has values for image width, height, type, attributes, mime type, bits, * and channels. * * @param string $path The filesystem path to the image for which to get properties. * * @return object * * @since 11.3 * @throws InvalidArgumentException * @throws RuntimeException */ public static function getImageFileProperties($path) { // Make sure the file exists. if (!file_exists($path)) { throw new InvalidArgumentException('The image file does not exist.'); } // Get the image file information. $info = getimagesize($path); if (!$info) { // @codeCoverageIgnoreStart throw new RuntimeException('Unable to get properties for the image.'); // @codeCoverageIgnoreEnd } // Build the response object. $properties = (object) array( 'width' => $info[0], 'height' => $info[1], 'type' => $info[2], 'attributes' => $info[3], 'bits' => isset($info['bits']) ? $info['bits'] : null, 'channels' => isset($info['channels']) ? $info['channels'] : null, 'mime' => $info['mime'] ); return $properties; } /** * Method to crop the current image. * * @param mixed $width The width of the image section to crop in pixels or a percentage. * @param mixed $height The height of the image section to crop in pixels or a percentage. * @param integer $left The number of pixels from the left to start cropping. * @param integer $top The number of pixels from the top to start cropping. * @param bool $createNew If true the current image will be cloned, cropped and returned; else * the current image will be cropped and returned. * * @return JImage * * @since 11.3 * @throws LogicException */ public function crop($width, $height, $left, $top, $createNew = true) { // Make sure the resource handle is valid. if (!$this->isLoaded()) { throw new LogicException('No valid image was loaded.'); } // Sanitize width. $width = $this->sanitizeWidth($width, $height); // Sanitize height. $height = $this->sanitizeHeight($height, $width); // Sanitize left. $left = $this->sanitizeOffset($left); // Sanitize top. $top = $this->sanitizeOffset($top); // Create the new truecolor image handle. $handle = imagecreatetruecolor($width, $height); // Allow transparency for the new image handle. imagealphablending($handle, false); imagesavealpha($handle, true); if ($this->isTransparent()) { // Get the transparent color values for the current image. $rgba = imageColorsForIndex($this->handle, imagecolortransparent($this->handle)); $color = imageColorAllocate($this->handle, $rgba['red'], $rgba['green'], $rgba['blue']); // Set the transparent color values for the new image. imagecolortransparent($handle, $color); imagefill($handle, 0, 0, $color); imagecopyresized($handle, $this->handle, 0, 0, $left, $top, $width, $height, $width, $height); } else { imagecopyresampled($handle, $this->handle, 0, 0, $left, $top, $width, $height, $width, $height); } // If we are cropping to a new image, create a new JImage object. if ($createNew) { // @codeCoverageIgnoreStart $new = new JImage($handle); return $new; // @codeCoverageIgnoreEnd } // Swap out the current handle for the new image handle. else { $this->handle = $handle; return $this; } } /** * Method to apply a filter to the image by type. Two examples are: grayscale and sketchy. * * @param string $type The name of the image filter to apply. * @param array $options An array of options for the filter. * * @return JImage * * @since 11.3 * @see JImageFilter * @throws LogicException * @throws RuntimeException */ public function filter($type, array $options = array()) { // Make sure the resource handle is valid. if (!$this->isLoaded()) { throw new LogicException('No valid image was loaded.'); } // Get the image filter instance. $filter = $this->getFilterInstance($type); // Execute the image filter. $filter->execute($options); return $this; } /** * Method to get the height of the image in pixels. * * @return integer * * @since 11.3 * @throws LogicException */ public function getHeight() { // Make sure the resource handle is valid. if (!$this->isLoaded()) { throw new LogicException('No valid image was loaded.'); } return imagesy($this->handle); } /** * Method to get the width of the image in pixels. * * @return integer * * @since 11.3 * @throws LogicException */ public function getWidth() { // Make sure the resource handle is valid. if (!$this->isLoaded()) { throw new LogicException('No valid image was loaded.'); } return imagesx($this->handle); } /** * Method to return the path * * @return string * * @since 11.3 */ public function getPath() { return $this->path; } /** * Method to determine whether or not an image has been loaded into the object. * * @return bool * * @since 11.3 */ public function isLoaded() { // Make sure the resource handle is valid. if (!is_resource($this->handle) || (get_resource_type($this->handle) != 'gd')) { return false; } return true; } /** * Method to determine whether or not the image has transparency. * * @return bool * * @since 11.3 * @throws LogicException */ public function isTransparent() { // Make sure the resource handle is valid. if (!$this->isLoaded()) { throw new LogicException('No valid image was loaded.'); } return (imagecolortransparent($this->handle) >= 0); } /** * 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) { // Make sure the file exists. if (!file_exists($path)) { throw new InvalidArgumentException('The image file does not exist.'); } // Get the image properties. $properties = self::getImageFileProperties($path); // Attempt to load the image based on the MIME-Type switch ($properties->mime) { case 'image/gif': // Make sure the image type is supported. if (empty(self::$formats[IMAGETYPE_GIF])) { // @codeCoverageIgnoreStart JLog::add('Attempting to load an image of unsupported type GIF.', JLog::ERROR); throw new RuntimeException('Attempting to load an image of unsupported type GIF.'); // @codeCoverageIgnoreEnd } // Attempt to create the image handle. $handle = imagecreatefromgif($path); if (!is_resource($handle)) { // @codeCoverageIgnoreStart throw new RuntimeException('Unable to process GIF image.'); // @codeCoverageIgnoreEnd } $this->handle = $handle; break; case 'image/jpeg': // Make sure the image type is supported. if (empty(self::$formats[IMAGETYPE_JPEG])) { // @codeCoverageIgnoreStart JLog::add('Attempting to load an image of unsupported type JPG.', JLog::ERROR); throw new RuntimeException('Attempting to load an image of unsupported type JPG.'); // @codeCoverageIgnoreEnd } // Attempt to create the image handle. $handle = imagecreatefromjpeg($path); if (!is_resource($handle)) { // @codeCoverageIgnoreStart throw new RuntimeException('Unable to process JPG image.'); // @codeCoverageIgnoreEnd } $this->handle = $handle; break; case 'image/png': // Make sure the image type is supported. if (empty(self::$formats[IMAGETYPE_PNG])) { // @codeCoverageIgnoreStart JLog::add('Attempting to load an image of unsupported type PNG.', JLog::ERROR); throw new RuntimeException('Attempting to load an image of unsupported type PNG.'); // @codeCoverageIgnoreEnd } // Attempt to create the image handle. $handle = imagecreatefrompng($path); if (!is_resource($handle)) { // @codeCoverageIgnoreStart throw new RuntimeException('Unable to process PNG image.'); // @codeCoverageIgnoreEnd } $this->handle = $handle; break; default: JLog::add('Attempting to load an image of unsupported type: ' . $properties->mime, JLog::ERROR); throw new InvalidArgumentException('Attempting to load an image of unsupported type: ' . $properties->mime); break; } // Set the filesystem path to the source image. $this->path = $path; } /** * Method to resize the current image. * * @param mixed $width The width of the resized image in pixels or a percentage. * @param mixed $height The height of the resized image in pixels or a percentage. * @param bool $createNew If true the current image will be cloned, resized and returned; else * the current image will be resized and returned. * @param integer $scaleMethod Which method to use for scaling * * @return JImage * * @since 11.3 * @throws LogicException */ public function resize($width, $height, $createNew = true, $scaleMethod = self::SCALE_INSIDE) { // Make sure the resource handle is valid. if (!$this->isLoaded()) { throw new LogicException('No valid image was loaded.'); } // Sanitize width. $width = $this->sanitizeWidth($width, $height); // Sanitize height. $height = $this->sanitizeHeight($height, $width); // Prepare the dimensions for the resize operation. $dimensions = $this->prepareDimensions($width, $height, $scaleMethod); // Create the new truecolor image handle. $handle = imagecreatetruecolor($dimensions->width, $dimensions->height); // Allow transparency for the new image handle. imagealphablending($handle, false); imagesavealpha($handle, true); if ($this->isTransparent()) { // Get the transparent color values for the current image. $rgba = imageColorsForIndex($this->handle, imagecolortransparent($this->handle)); $color = imageColorAllocate($this->handle, $rgba['red'], $rgba['green'], $rgba['blue']); // Set the transparent color values for the new image. imagecolortransparent($handle, $color); imagefill($handle, 0, 0, $color); imagecopyresized($handle, $this->handle, 0, 0, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight()); } else { imagecopyresampled($handle, $this->handle, 0, 0, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight()); } // If we are resizing to a new image, create a new JImage object. if ($createNew) { // @codeCoverageIgnoreStart $new = new JImage($handle); return $new; // @codeCoverageIgnoreEnd } // Swap out the current handle for the new image handle. else { $this->handle = $handle; return $this; } } /** * Method to rotate the current image. * * @param mixed $angle The angle of rotation for the image * @param integer $background The background color to use when areas are added due to rotation * @param bool $createNew If true the current image will be cloned, rotated and returned; else * the current image will be rotated and returned. * * @return JImage * * @since 11.3 * @throws LogicException */ public function rotate($angle, $background = -1, $createNew = true) { // Make sure the resource handle is valid. if (!$this->isLoaded()) { throw new LogicException('No valid image was loaded.'); } // Sanitize input $angle = floatval($angle); // Create the new truecolor image handle. $handle = imagecreatetruecolor($this->getWidth(), $this->getHeight()); // Allow transparency for the new image handle. imagealphablending($handle, false); imagesavealpha($handle, true); // Copy the image imagecopy($handle, $this->handle, 0, 0, 0, 0, $this->getWidth(), $this->getHeight()); // Rotate the image $handle = imagerotate($handle, $angle, $background); // If we are resizing to a new image, create a new JImage object. if ($createNew) { // @codeCoverageIgnoreStart $new = new JImage($handle); return $new; // @codeCoverageIgnoreEnd } // Swap out the current handle for the new image handle. else { $this->handle = $handle; return $this; } } /** * Method to write the current image out to a file. * * @param string $path The filesystem path to save the image. * @param integer $type The image type to save the file as. * @param array $options The image type options to use in saving the file. * * @return void * * @see http://www.php.net/manual/image.constants.php * @since 11.3 * @throws LogicException */ public function toFile($path, $type = IMAGETYPE_JPEG, array $options = array()) { // Make sure the resource handle is valid. if (!$this->isLoaded()) { throw new LogicException('No valid image was loaded.'); } switch ($type) { case IMAGETYPE_GIF: imagegif($this->handle, $path); break; case IMAGETYPE_PNG: imagepng($this->handle, $path, (array_key_exists('quality', $options)) ? $options['quality'] : 0); break; case IMAGETYPE_JPEG: default: imagejpeg($this->handle, $path, (array_key_exists('quality', $options)) ? $options['quality'] : 100); } } /** * Method to get an image filter instance of a specified type. * * @param string $type The image filter type to get. * * @return JImageFilter * * @since 11.3 * @throws RuntimeException */ protected function getFilterInstance($type) { // Sanitize the filter type. $type = strtolower(preg_replace('#[^A-Z0-9_]#i', '', $type)); // Verify that the filter type exists. $className = 'JImageFilter' . ucfirst($type); if (!class_exists($className)) { JLog::add('The ' . ucfirst($type) . ' image filter is not available.', JLog::ERROR); throw new RuntimeException('The ' . ucfirst($type) . ' image filter is not available.'); } // Instantiate the filter object. $instance = new $className($this->handle); // Verify that the filter type is valid. if (!($instance instanceof JImageFilter)) { // @codeCoverageIgnoreStart JLog::add('The ' . ucfirst($type) . ' image filter is not valid.', JLog::ERROR); throw new RuntimeException('The ' . ucfirst($type) . ' image filter is not valid.'); // @codeCoverageIgnoreEnd } return $instance; } /** * Method to get the new dimensions for a resized image. * * @param integer $width The width of the resized image in pixels. * @param integer $height The height of the resized image in pixels. * @param integer $scaleMethod The method to use for scaling * * @return object * * @since 11.3 * @throws InvalidArgumentException */ protected function prepareDimensions($width, $height, $scaleMethod) { // Instantiate variables. $dimensions = new stdClass; switch ($scaleMethod) { case self::SCALE_FILL: $dimensions->width = intval(round($width)); $dimensions->height = intval(round($height)); break; case self::SCALE_INSIDE: case self::SCALE_OUTSIDE: $rx = $this->getWidth() / $width; $ry = $this->getHeight() / $height; if ($scaleMethod == self::SCALE_INSIDE) { $ratio = ($rx > $ry) ? $rx : $ry; } else { $ratio = ($rx < $ry) ? $rx : $ry; } $dimensions->width = intval(round($this->getWidth() / $ratio)); $dimensions->height = intval(round($this->getHeight() / $ratio)); break; default: throw new InvalidArgumentException('Invalid scale method.'); break; } return $dimensions; } /** * Method to sanitize a height value. * * @param mixed $height The input height value to sanitize. * @param mixed $width The input width value for reference. * * @return integer * * @since 11.3 */ protected function sanitizeHeight($height, $width) { // If no height was given we will assume it is a square and use the width. $height = ($height === null) ? $width : $height; // If we were given a percentage, calculate the integer value. if (preg_match('/^[0-9]+(\.[0-9]+)?\%$/', $height)) { $height = intval(round($this->getHeight() * floatval(str_replace('%', '', $height)) / 100)); } // Else do some rounding so we come out with a sane integer value. else { $height = intval(round(floatval($height))); } return $height; } /** * Method to sanitize an offset value like left or top. * * @param mixed $offset An offset value. * * @return integer * * @since 11.3 */ protected function sanitizeOffset($offset) { return intval(round(floatval($offset))); } /** * Method to sanitize a width value. * * @param mixed $width The input width value to sanitize. * @param mixed $height The input height value for reference. * * @return integer * * @since 11.3 */ protected function sanitizeWidth($width, $height) { // If no width was given we will assume it is a square and use the height. $width = ($width === null) ? $height : $width; // If we were given a percentage, calculate the integer value. if (preg_match('/^[0-9]+(\.[0-9]+)?\%$/', $width)) { $width = intval(round($this->getWidth() * floatval(str_replace('%', '', $width)) / 100)); } // Else do some rounding so we come out with a sane integer value. else { $width = intval(round(floatval($width))); } return $width; } } home/academiac/www/libraries/joomla/html/html/image.php000064400000012124151372740640017160 0ustar00getTemplate(); // Strip HTML. $alt = html_entity_decode($alt, ENT_COMPAT, 'UTF-8'); if ($altFile) { $src = $altFolder . $altFile; } elseif ($altFile == -1) { return ''; } else { $path = JPATH_SITE . '/templates/' . $cur_template . '/images/' . $file; if (!isset($paths[$path])) { if (file_exists(JPATH_SITE . '/templates/' . $cur_template . '/images/' . $file)) { $paths[$path] = 'templates/' . $cur_template . '/images/' . $file; } else { // Outputs only path to image. $paths[$path] = $folder . $file; } } $src = $paths[$path]; } if (substr($src, 0, 1) == "/") { $src = substr_replace($src, '', 0, 1); } // Prepend the base path. $src = JURI::base(true) . '/' . $src; // Outputs actual HTML tag. if ($asTag) { return '' . $alt . ''; } return $src; } /** * Checks to see if an image exists in the current templates image directory * if it does it loads this image. Otherwise the default image is loaded. * Also can be used in conjunction with the menulist param to create the chosen image * load the default or use no image * * @param string $file The file name, eg foobar.png. * @param string $folder The path to the image. * @param integer $altFile Empty: use $file and $folder, -1: show no image, not-empty: use $altFile and $altFolder. * @param string $altFolder Another path. Only used for the contact us form based on the value of the imagelist param. * @param string $alt Alternative text. * @param array $attribs An associative array of attributes to add. * @param boolean $asTag True (default) to display full tag, false to return just the path. * * @return string The src or the full img tag if $asTag is true. * * @since 11.1 * * @deprecated 12.1 */ public static function administrator($file, $folder = '/images/', $altFile = null, $altFolder = '/images/', $alt = null, $attribs = null, $asTag = true) { // Deprecation warning. JLog::add('JImage::administrator is deprecated.', JLog::WARNING, 'deprecated'); $app = JFactory::getApplication(); if (is_array($attribs)) { $attribs = JArrayHelper::toString($attribs); } $cur_template = $app->getTemplate(); // Strip HTML. $alt = html_entity_decode($alt, ENT_COMPAT, 'UTF-8'); if ($altFile) { $image = $altFolder . $altFile; } elseif ($altFile == -1) { $image = ''; } else { if (file_exists(JPATH_ADMINISTRATOR . '/templates/' . $cur_template . '/images/' . $file)) { $image = 'templates/' . $cur_template . '/images/' . $file; } else { // Compatibility with previous versions. if (substr($folder, 0, 14) == "/administrator") { $image = substr($folder, 15) . $file; } else { $image = $folder . $file; } } } if (substr($image, 0, 1) == "/") { $image = substr_replace($image, '', 0, 1); } // Prepend the base path. $image = JURI::base(true) . '/' . $image; // Outputs actual HTML tag. if ($asTag) { $image = '' . $alt . ''; } return $image; } }