static function image($config, $item, $only_url = false, $pm = false, $links = false) { if (!($config['news_content_image_pos'] != 'disabled' || $pm || $links)) { return ''; } $IMG_SOURCE = ''; $item['title'] = str_replace('"', """, $item['title']); $uri = JURI::getInstance(); $IMG_LINK = static::itemLink($item, $config); // if (trim($item['image']) != '') { $image_path = str_replace(array('user:'******'post:'), '', $item['image']); if (stripos($item['image'], 'user:'******'images/easyblog_images/' . $image_path; } else { $IMG_SOURCE = 'images/easyblog_articles/' . $image_path; } } else { // set image to first in article content $IMG_SOURCE = NSP_GK5_com_easyblog_View::getImageFromText($item['text']); } // $full_size_img = $IMG_SOURCE; // if ($config['create_thumbs'] == 1 && $IMG_SOURCE != '') { // try to override standard image if (strpos($IMG_SOURCE, 'http://') == FALSE) { $img_file = NSP_GK5_Thumbs::createThumbnail($IMG_SOURCE, $config, false, false, '', $links); if (is_array($img_file)) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/' . $img_file[1]; } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } else { $IMG_SOURCE = ''; } } } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } return NSP_GK5_com_easyblog_View::getImageHTML($only_url, $IMG_SOURCE, $links, $config, $IMG_LINK, $full_size_img); }
static function image($config, $item, $only_url = false, $pm = false, $links = false) { if ($config['news_content_image_pos'] != 'disabled' || $pm || $links) { $item['title'] = str_replace('"', """, $item['title']); $IMG_SOURCE = ''; $IMG_LINK = static::itemLink($item); $uri = JURI::getInstance(); // get image from Joomla! Images and Links settings $IMG_SOURCE = static::originalImage($config, $item); // $full_size_img = $IMG_SOURCE; // if ($config['create_thumbs'] == 1 && $IMG_SOURCE != '') { // try to override standard image if (strpos($IMG_SOURCE, 'http://') == FALSE) { $img_file = NSP_GK5_Thumbs::createThumbnail($IMG_SOURCE, $config, false, false, '', $links); if (is_array($img_file)) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/' . $img_file[1]; } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } else { $IMG_SOURCE = ''; } } } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } // Retrieve alt text $alt_text = NSP_GK5_com_content_View::getAltText($config, $item); return NSP_GK5_com_content_View::getImageHTML($only_url, $IMG_SOURCE, $links, $config, $IMG_LINK, $full_size_img, $alt_text); } else { return ''; } }
static function image($config, $item, $only_url = false, $pm = false, $links = false) { if (!($item['type'] == 'photo' && ($config['news_content_image_pos'] != 'disabled' || $pm || $links))) { return ''; } $IMG_SOURCE = ''; $IMG_LINK = static::itemLink($item, $config); $uri = JURI::getInstance(); // if (JFile::exists(JPATH_SITE . DS . $item['image'])) { $IMG_SOURCE = $item['image']; } // $full_size_img = $IMG_SOURCE; // if ($config['create_thumbs'] == 1 && $IMG_SOURCE != '') { // try to override standard image if (strpos($IMG_SOURCE, 'http://') == FALSE) { $img_file = NSP_GK5_Thumbs::createThumbnail($IMG_SOURCE, $config, false, false, '', $links); if (is_array($img_file)) { $uri = JURI::getInstance(); $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/' . $img_file[1]; } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } else { $IMG_SOURCE = ''; } } } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } return NSP_GK5_jomsocial_View::getImageHTML($only_url, $IMG_SOURCE, $links, $config, $IMG_LINK, $full_size_img); }
static function image($config, $item, $only_url = false, $pm = false, $links = false) { if (!($config['news_content_image_pos'] != 'disabled' || $pm || $links)) { return ''; } $news_title = str_replace('"', """, $item['title']); $IMG_SOURCE = 'media' . DS . 'com_hikashop' . DS . 'upload' . DS . $item['image']; $IMG_LINK = static::itemLink($item, $config); // $full_size_img = $IMG_SOURCE; // if ($config['create_thumbs'] == 1 && $IMG_SOURCE != '') { // try to override standard image if (strpos($IMG_SOURCE, 'http://') == FALSE) { $img_file = NSP_GK5_Thumbs::createThumbnail($IMG_SOURCE, $config, false, false, '', $links, true); if (is_array($img_file)) { $uri = JURI::getInstance(); $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/' . $img_file[1]; } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } else { $IMG_SOURCE = ''; } } } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } // return NSP_GK5_com_hikashop_View::getImageHTML($only_url, $IMG_SOURCE, $links, $config, $IMG_LINK, $full_size_img); }
static function image($config, $item, $only_url = false, $pm = false, $links = false) { if ($config['news_content_image_pos'] != 'disabled' || $pm || $links) { $item['title'] = str_replace('"', """, $item['title']); $IMG_SOURCE = ''; $IMG_LINK = $item['url']; // $uri = JURI::getInstance(); // get image from Joomla! Images and Links settings $IMG_SOURCE = $item['image']; // $full_size_img = $IMG_SOURCE; // if ($config['create_thumbs'] == 1 && $IMG_SOURCE != '') { // try to override standard image if (strpos($IMG_SOURCE, 'http://') == FALSE) { $img_file = NSP_GK5_Thumbs::createThumbnail($IMG_SOURCE, $config, false, false, '', $links); if (is_array($img_file)) { $uri = JURI::getInstance(); $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/' . $img_file[1]; } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } else { $IMG_SOURCE = ''; } } } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } if ($only_url) { return $IMG_SOURCE; } else { // if ($IMG_SOURCE != '') { $class = ''; if (!$links) { $class = ' t' . $config['news_content_image_pos'] . ' f' . $config['news_content_image_float']; } $size = ''; $margins = ''; // if (!$links && $config['responsive_images'] == 1) { $class .= ' gkResponsive'; } // if (!$links) { if ($config['img_width'] != 0 && !$config['img_keep_aspect_ratio'] && $config['responsive_images'] == 0) { $size .= 'width:' . $config['img_width'] . 'px;'; } if ($config['img_height'] != 0 && !$config['img_keep_aspect_ratio'] && $config['responsive_images'] == 0) { $size .= 'height:' . $config['img_height'] . 'px;'; } if ($config['img_margin'] != '') { $margins = ' style="margin:' . $config['img_margin'] . ';"'; } } else { if ($config['links_img_width'] != 0 && !$config['img_keep_aspect_ratio'] && $config['responsive_images'] == 0) { $size .= 'width:' . $config['links_img_width'] . 'px;'; } if ($config['links_img_height'] != 0 && !$config['img_keep_aspect_ratio'] && $config['responsive_images'] == 0) { $size .= 'height:' . $config['links_img_height'] . 'px;'; } if ($config['links_img_margin'] != '') { $margins = ' style="margin:' . $config['links_img_margin'] . ';"'; } } // if ($config['news_image_link'] == 1 || $links) { if ($config['news_image_modal'] == 1) { return $config['news_content_image_pos'] == 'center' && !$links ? '<div class="center' . $class . '"><a href="' . $full_size_img . '" class="modal nspImageWrapper' . $class . '"' . $margins . ' target="' . $config['open_links_window'] . '"><img class="nspImage" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></a></div>' : '<a href="' . $full_size_img . '" class="modal nspImageWrapper' . $class . '"' . $margins . ' target="' . $config['open_links_window'] . '"><img class="nspImage' . $class . '" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></a>'; } else { return $config['news_content_image_pos'] == 'center' && !$links ? '<div class="center' . $class . '"><a href="' . $IMG_LINK . '" class="nspImageWrapper' . $class . '"' . $margins . ' target="' . $config['open_links_window'] . '"><img class="nspImage" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></a></div>' : '<a href="' . $IMG_LINK . '" class="nspImageWrapper' . $class . '"' . $margins . ' target="' . $config['open_links_window'] . '"><img class="nspImage' . $class . '" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></a>'; } } else { return $config['news_content_image_pos'] == 'center' && !$links ? '<div class="center' . $class . '"><span class="nspImageWrapper' . $class . '"' . $margins . '><img class="nspImage" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" ' . $size . ' /></span></div>' : '<span class="nspImageWrapper' . $class . '"' . $margins . '><img class="nspImage' . $class . '" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></span>'; } } else { return ''; } } } else { return ''; } }
static function createThumbnail($path, $config, $k2_mode = false, $vm_mode = false, $img_rel = '', $links = false, $hikashop_mode = false, $solidres_mode = false) { if ($config['use_curl_download'] == 0 && (stripos($path, 'http://') || stripos($path, 'https://'))) { return false; } // importing classes jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.path'); //script configuration - increase memory limit to selected value ini_set('memory_limit', $config['memory_limit']); // cache dir $cache_dir = JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS; // downloaded and filename variables $downloaded = false; $imgname = ''; // check if the file is external if (strpos($path, 'http://') !== FALSE || strpos($path, 'https://') !== FALSE) { // check if the file was downloaded $imgname = ''; $slashpos = strrpos($path, '/'); $imgname = substr($path, $slashpos + 1); // check if the file exists if (!file_exists(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'downloaded' . DS . $imgname)) { // if not - download the file if (function_exists('curl_init')) { // initializing connection $curl = curl_init(); // saves us before putting directly results of request curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // check the source of request curl_setopt($curl, CURLOPT_URL, $path); // timeout in seconds curl_setopt($curl, CURLOPT_TIMEOUT, 20); // useragent curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // reading content $img_content = curl_exec($curl); // closing connection curl_close($curl); // check the results (curl_exec return FALSE on failure) and its length if ($img_content !== FALSE && strlen($img_content) > 0) { // save the downloaded image $fp = fopen(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'downloaded' . DS . $imgname, 'x'); fwrite($fp, $img_content); fclose($fp); // change the path to the downloaded file $path = 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'downloaded' . DS . $imgname; $downloaded = true; } else { return false; } } else { return false; } } else { $path = 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'downloaded' . DS . $imgname; $downloaded = true; } } // checking the special images $check_result = NSP_GK5_Thumbs::checkSpecialImages(NSP_GK5_Thumbs::translateName($path, $config['module_id'], $k2_mode, $vm_mode, '', $downloaded, $imgname, $links, $hikashop_mode, $solidres_mode)); // preparing an array with the image class values $img_rels = array(); // check if any classes exists in the image if ($img_rel !== '') { $img_rels = explode(' ', $img_rel); } // no scale images if ($check_result == 2) { // NOSCALE if (NSP_GK5_Thumbs::checkCache(NSP_GK5_Thumbs::translateName($path, $config['module_id'], $k2_mode, $vm_mode, '_noscale', $downloaded, $imgname, $links), false, $config['module_id'], $hikashop_mode, $solidres_mode)) { return array(TRUE, NSP_GK5_Thumbs::translateName($path, $config['module_id'], $k2_mode, $vm_mode, '_noscale', $downloaded, $imgname, $links, $hikashop_mode, $solidres_mode)); } else { // file path $file = NSP_GK5_Thumbs::getRealPath($path, $k2_mode, $vm_mode, '_noscale', $hikashop_mode, $solidres_mode); // filename $filename = NSP_GK5_Thumbs::translateName($path, $config['module_id'], $k2_mode, $vm_mode, '_noscale', $downloaded, $imgname, $links, $hikashop_mode, $solidres_mode); // Getting informations about image if (is_file($file)) { $imageData = getimagesize($file); $img_w = str_replace('px', '', str_replace('%', '', $links ? $config['links_img_width'] : $config['img_width'])); $img_h = str_replace('px', '', str_replace('%', '', $links ? $config['links_img_height'] : $config['img_height'])); // loading image depends from type of image if ($imageData['mime'] == 'image/jpeg' || $imageData['mime'] == 'image/pjpeg' || $imageData['mime'] == 'image/jpg') { $imageSource = @imagecreatefromjpeg($file); } elseif ($imageData['mime'] == 'image/gif') { $imageSource = @imagecreatefromgif($file); } else { $imageSource = @imagecreatefrompng($file); } // here can be exist an error when image is to big - then class return blank page // setting image size in variables $imageSourceWidth = imagesx($imageSource); $imageSourceHeight = imagesy($imageSource); $imageBG = imagecreatetruecolor($img_w, $img_h); // If image is JPG or GIF if ($imageData['mime'] == 'image/png') { $imageBG = imagecreatetruecolor($img_w, $img_h); // enable transparent background if ($config['img_bg'] == 'transparent') { // create transparent color $rgb = imagecolorallocatealpha($imageBG, 0, 0, 0, 127); } else { // create normal color $bg = $config['img_bg']; // translate hex to RGB $hex_color = strtolower(trim($bg, '#;&Hh')); $bg = array_map('hexdec', explode('.', wordwrap($hex_color, ceil(strlen($hex_color) / 3), '.', 1))); // creating color $rgb = imagecolorallocate($imageBG, $bg[0], $bg[1], $bg[2]); } // filling the canvas imagefill($imageBG, 0, 0, $rgb); // enabling transparent settings for better quality imagealphablending($imageBG, false); imagesavealpha($imageBG, true); } // $imageSourceNWidth = $img_w; $imageSourceNHeight = $img_h; $base_x = 0; $base_y = 0; // copy image imagecopyresampled($imageBG, $imageSource, $base_x, $base_y, 0, 0, $imageSourceNWidth, $imageSourceNHeight, $imageSourceWidth, $imageSourceHeight); // save image depends from MIME type if ($imageData['mime'] == 'image/jpeg' || $imageData['mime'] == 'image/pjpeg' || $imageData['mime'] == 'image/jpg') { imagejpeg($imageBG, $cache_dir . $filename, $config['img_quality']); } elseif ($imageData['mime'] == 'image/gif') { imagegif($imageBG, $cache_dir . $filename); } else { imagepng($imageBG, $cache_dir . $filename); } // result return array(TRUE, $filename); } else { return FALSE; } } } else { // cropped or normal image if (NSP_GK5_Thumbs::checkCache(NSP_GK5_Thumbs::translateName($path, $config['module_id'], $k2_mode, $vm_mode, $check_result == 1 ? '_cropped' : '', $downloaded, $imgname, $links, $hikashop_mode, $solidres_mode), isset($config['thumbs_cache_time']) ? $config['thumbs_cache_time'] : '60', $config['module_id'])) { return array(TRUE, NSP_GK5_Thumbs::translateName($path, $config['module_id'], $k2_mode, $vm_mode, $check_result == 1 ? '_cropped' : '', $downloaded, $imgname, $links, $hikashop_mode, $solidres_mode)); } else { // file path $file = NSP_GK5_Thumbs::getRealPath($path, $k2_mode, $vm_mode, $check_result == 1 ? '_cropped' : '', $hikashop_mode, $solidres_mode); // filename $filename = NSP_GK5_Thumbs::translateName($path, $config['module_id'], $k2_mode, $vm_mode, $check_result == 1 ? '_cropped' : '', $downloaded, $imgname, $links, $hikashop_mode, $solidres_mode); // Getting informations about image if (is_file($file)) { $imageData = getimagesize($file); $img_w = str_replace('px', '', str_replace('%', '', $links ? $config['links_img_width'] : $config['img_width'])); $img_h = str_replace('px', '', str_replace('%', '', $links ? $config['links_img_height'] : $config['img_height'])); // loading image depends from type of image if ($imageData['mime'] == 'image/jpeg' || $imageData['mime'] == 'image/pjpeg' || $imageData['mime'] == 'image/jpg') { $imageSource = @imagecreatefromjpeg($file); } elseif ($imageData['mime'] == 'image/gif') { $imageSource = @imagecreatefromgif($file); } else { $imageSource = @imagecreatefrompng($file); } // check if the proper image resource was created if (!$imageSource) { return FALSE; } // here can be exist an error when image is to big - then class return blank page // setting image size in variables $imageSourceWidth = imagesx($imageSource); $imageSourceHeight = imagesy($imageSource); // variables for cropping $top_crop = floor($imageSourceHeight * $config['simple_crop_top'] / 100); $bottom_crop = floor($imageSourceHeight * $config['simple_crop_bottom'] / 100); $left_crop = floor($imageSourceWidth * $config['simple_crop_left'] / 100); $right_crop = floor($imageSourceWidth * $config['simple_crop_right'] / 100); // get the cropping rules foreach ($config['crop_rules'] as $rule) { if (is_string($rule['type']) && count($img_rels)) { foreach ($img_rels as $rel) { if ($rule['type'] == $rel) { $top_crop = $rule['top']; $bottom_crop = $rule['bottom']; $left_crop = $rule['left']; $right_crop = $rule['right']; break; } } } else { if ($rule['type']['width'] == $imageSourceWidth && $rule['type']['height'] == $imageSourceHeight) { $top_crop = $rule['top']; $bottom_crop = $rule['bottom']; $left_crop = $rule['left']; $right_crop = $rule['right']; break; } } } // Creating blank canvas if ($config['img_keep_aspect_ratio']) { // calculate ratio for first scaling $ratio = $imageSourceWidth > $imageSourceHeight ? $img_w / $imageSourceWidth : $img_h / $imageSourceHeight; // calculate new image size $imageSourceNWidth = ($imageSourceWidth - ($left_crop + $right_crop)) * $ratio; $imageSourceNHeight = ($imageSourceHeight - ($top_crop + $bottom_crop)) * $ratio; // calculate ratio for second scaling if ($img_w > $img_h) { if ($imageSourceNHeight > $img_h) { $ratio2 = $img_h / $imageSourceNHeight; $imageSourceNHeight *= $ratio2; $imageSourceNWidth *= $ratio2; } } else { if ($imageSourceNWidth > $img_w) { $ratio2 = $img_w / $imageSourceNWidth; $imageSourceNHeight *= $ratio2; $imageSourceNWidth *= $ratio2; } } $img_w = $imageSourceNWidth; $img_h = $imageSourceNHeight; } $imageBG = imagecreatetruecolor($img_w, $img_h); // If image is JPG or GIF if ($imageData['mime'] == 'image/jpeg' || $imageData['mime'] == 'image/pjpeg' || $imageData['mime'] == 'image/jpg' || $imageData['mime'] == 'image/gif') { // when bg is set to transparent - use black background if ($config['img_bg'] == 'transparent') { $bgColorR = 0; $bgColorG = 0; $bgColorB = 0; } else { // in other situation - translate hex to RGB $bg = $config['img_bg']; if (strlen($bg) == 4) { $bg = $bg[0] . $bg[1] . $bg[1] . $bg[2] . $bg[2] . $bg[3] . $bg[3]; } $hex_color = strtolower(trim($bg, '#;&Hh')); $bg = array_map('hexdec', explode('.', wordwrap($hex_color, ceil(strlen($hex_color) / 3), '.', 1))); $bgColorR = $bg[0]; $bgColorG = $bg[1]; $bgColorB = $bg[2]; } // Creating color $rgb = imagecolorallocate($imageBG, $bgColorR, $bgColorG, $bgColorB); // filling canvas with new color imagefill($imageBG, 0, 0, $rgb); } else { // for PNG images if ($config['img_keep_aspect_ratio']) { // calculate ratio for first scaling $ratio = $imageSourceWidth > $imageSourceHeight ? $img_w / $imageSourceWidth : $img_h / $imageSourceHeight; // calculate new image size $imageSourceNWidth = ($imageSourceWidth - ($left_crop + $right_crop)) * $ratio; $imageSourceNHeight = ($imageSourceHeight - ($top_crop + $bottom_crop)) * $ratio; // calculate ratio for second scaling if ($img_w > $img_h) { if ($imageSourceNHeight > $img_h) { $ratio2 = $img_h / $imageSourceNHeight; $imageSourceNHeight *= $ratio2; $imageSourceNWidth *= $ratio2; } } else { if ($imageSourceNWidth > $img_w) { $ratio2 = $img_w / $imageSourceNWidth; $imageSourceNHeight *= $ratio2; $imageSourceNWidth *= $ratio2; } } $img_w = $imageSourceNWidth; $img_h = $imageSourceNHeight; } $imageBG = imagecreatetruecolor($img_w, $img_h); // enable transparent background if ($config['img_bg'] == 'transparent') { // create transparent color $rgb = imagecolorallocatealpha($imageBG, 0, 0, 0, 127); } else { // create normal color $bg = $config['img_bg']; // translate hex to RGB $hex_color = strtolower(trim($bg, '#;&Hh')); $bg = array_map('hexdec', explode('.', wordwrap($hex_color, ceil(strlen($hex_color) / 3), '.', 1))); // creating color $rgb = imagecolorallocate($imageBG, $bg[0], $bg[1], $bg[2]); } // filling the canvas imagefill($imageBG, 0, 0, $rgb); // enabling transparent settings for better quality imagealphablending($imageBG, false); imagesavealpha($imageBG, true); } // when stretching is disabled if (!$config['img_stretch']) { if ($config['img_keep_aspect_ratio']) { $base_x = 0; $base_y = 0; $imageSourceNWidth = $img_w; $imageSourceNHeight = $img_h; } else { // if image auto-scale is enabled if ($config['img_auto_scale'] && !$config['img_keep_aspect_ratio']) { $img_ratio = $imageSourceWidth / $imageSourceHeight; $thumb_ratio = $img_w / $img_h; // base variables $imageSourceNWidth = $img_w; $imageSourceNHeight = $img_h; $base_x = 0; $base_y = 0; // if img_ratio == thumb_ratio - no scale and cuts $left_crop = 0; $top_crop = 0; // two other cases if ($img_ratio > $thumb_ratio) { // when source is wider than destination $ratio_h = $imageSourceHeight / $img_h; $new_w = $img_w * $ratio_h; $left_crop = floor(($imageSourceWidth - $new_w) / 2); // top_crop still 0 } else { if ($img_ratio < $thumb_ratio) { // when source is higher than destination $ratio_w = $imageSourceWidth / $img_w; $new_h = $img_h * $ratio_w; $top_crop = floor(($imageSourceHeight - $new_h) / 2); // left_crop still } } // equal two other crop params $right_crop = $left_crop; $bottom_crop = $top_crop; } else { // if not - left unused areas of the image // calculate ratio for first scaling $ratio = $imageSourceWidth - ($left_crop + $right_crop) > $imageSourceHeight - ($top_crop + $bottom_crop) ? $img_w / ($imageSourceWidth - ($left_crop + $right_crop)) : $img_h / ($imageSourceHeight - ($top_crop + $bottom_crop)); // calculate new image size $imageSourceNWidth = ($imageSourceWidth - ($left_crop + $right_crop)) * $ratio; $imageSourceNHeight = ($imageSourceHeight - ($top_crop + $bottom_crop)) * $ratio; // calculate ratio for second scaling if ($img_w > $img_h) { if ($imageSourceNHeight > $img_h) { $ratio2 = $img_h / $imageSourceNHeight; $imageSourceNHeight *= $ratio2; $imageSourceNWidth *= $ratio2; } } else { if ($imageSourceNWidth > $img_w) { $ratio2 = $img_w / $imageSourceNWidth; $imageSourceNHeight *= $ratio2; $imageSourceNWidth *= $ratio2; } } // setting position of putting thumbnail on canvas $base_x = floor(($img_w - $imageSourceNWidth) / 2); $base_y = floor(($img_h - $imageSourceNHeight) / 2); } } } else { // when stretching is enable $imageSourceNWidth = $img_w; $imageSourceNHeight = $img_h; $base_x = 0; $base_y = 0; } // copy image imagecopyresampled($imageBG, $imageSource, $base_x, $base_y, $left_crop, $top_crop, $imageSourceNWidth, $imageSourceNHeight, $imageSourceWidth - ($left_crop + $right_crop), $imageSourceHeight - ($top_crop + $bottom_crop)); // // applying filters // // grayscale if ($config['grayscale_filter'] || $config['sepia_filter']) { imagefilter($imageBG, IMG_FILTER_GRAYSCALE); } // sepia if ($config['sepia_filter']) { imagefilter($imageBG, IMG_FILTER_COLORIZE, 90, 60, 40); } // blur if ($config['blur_filter']) { imagefilter($imageBG, IMG_FILTER_GAUSSIAN_BLUR, $config['filter_arg']); } // brightness if ($config['brightness_filter']) { imagefilter($imageBG, IMG_FILTER_BRIGHTNESS, $config['filter_arg']); } // smooth if ($config['smooth_filter']) { imagefilter($imageBG, IMG_FILTER_SMOOTH, $config['filter_arg']); } // pixelate if ($config['pixelate_filter']) { imagefilter($imageBG, IMG_FILTER_PIXELATE, $config['filter_arg'], true); } // contrast if ($config['contrast_filter']) { imagefilter($imageBG, IMG_FILTER_CONTRAST, $config['filter_arg']); } // save image depends from MIME type if ($imageData['mime'] == 'image/jpeg' || $imageData['mime'] == 'image/pjpeg' || $imageData['mime'] == 'image/jpg') { imagejpeg($imageBG, $cache_dir . $filename, $config['img_quality']); } elseif ($imageData['mime'] == 'image/gif') { imagegif($imageBG, $cache_dir . $filename); } else { imagepng($imageBG, $cache_dir . $filename); } // result return array(TRUE, $filename); } else { return FALSE; } } } }
static function image($config, $item, $only_url = false, $pm = false) { if ($config['news_content_image_pos'] != 'disabled' || $pm) { $IMG_SOURCE = ''; $item['title'] = str_replace('"', """, $item['title']); $uri = JURI::getInstance(); // if (!$config['k2_image_size']) { $config['k2_image_size'] = 'Generic'; } // if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item['id']) . '_' . $config['k2_image_size'] . '.jpg')) { $IMG_SOURCE = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item['id']) . '_' . $config['k2_image_size'] . '.jpg'; } else { // set image to first in article content if (preg_match('/\\<img.*src=.*?\\>/', $item['text'])) { $imgStartPos = JString::strpos($item['text'], 'src="'); if ($imgStartPos) { $imgEndPos = JString::strpos($item['text'], '"', $imgStartPos + 5); } if ($imgStartPos > 0) { $IMG_SOURCE = JString::substr($item['text'], $imgStartPos + 5, $imgEndPos - ($imgStartPos + 5)); } } } // $full_size_img = $IMG_SOURCE; // if ($config['create_thumbs'] == 1 && $IMG_SOURCE != '') { // try to override standard image if (strpos($IMG_SOURCE, 'http://') == FALSE) { $img_file = NSP_GK5_Thumbs::createThumbnail(str_replace(JURI::root() . 'media', 'media', $IMG_SOURCE), $config, true); if (is_array($img_file)) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/' . $img_file[1]; } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } else { $IMG_SOURCE = ''; } } } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } if ($only_url) { return $IMG_SOURCE; } else { // if ($IMG_SOURCE != '') { $class = ' t' . $config['news_content_image_pos'] . ' f' . $config['news_content_image_float']; $size = ''; $margins = ''; // if ($config['responsive_images'] == 1) { $class .= ' gkResponsive'; } // if ($config['img_width'] != 0 && !$config['img_keep_aspect_ratio'] && $config['responsive_images'] == 0) { $size .= 'width:' . $config['img_width'] . 'px;'; } if ($config['img_height'] != 0 && !$config['img_keep_aspect_ratio'] && $config['responsive_images'] == 0) { $size .= 'height:' . $config['img_height'] . 'px;'; } if ($config['img_margin'] != '') { $margins = ' style="margin:' . $config['img_margin'] . ';"'; } // if ($config['news_image_link'] == 1) { if ($config['news_image_modal'] == 1) { return $config['news_content_image_pos'] == 'center' ? '<div class="center' . $class . '"><a href="' . $full_size_img . '" class="modal nspImageWrapper' . $class . '"' . $margins . '><img class="nspImage" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></a></div>' : '<a href="' . $full_size_img . '" class="modal nspImageWrapper' . $class . '"' . $margins . '><img class="nspImage' . $class . '" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></a>'; } else { $link = NSP_GK5_com_k2_View::itemLink($item); return $config['news_content_image_pos'] == 'center' ? '<div class="center' . $class . '"><a href="' . $link . '" class="nspImageWrapper' . $class . '"' . $margins . '><img class="nspImage" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></a></div>' : '<a href="' . $link . '" class="nspImageWrapper' . $class . '"' . $margins . '><img class="nspImage' . $class . '" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></a>'; } } else { return $config['news_content_image_pos'] == 'center' ? '<div class="center' . $class . '"><span class="nspImageWrapper' . $class . '"' . $margins . '><img class="nspImage" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" ' . $size . ' /></span></div>' : '<span class="nspImageWrapper' . $class . '"' . $margins . '><img class="nspImage' . $class . '" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></span>'; } } else { return ''; } } } else { return ''; } }
static function image($config, $item, $only_url = false, $pm = false, $links = false) { if ($config['news_content_image_pos'] != 'disabled' || $pm || $links) { $IMG_SOURCE = ''; $item['title'] = str_replace('"', """, $item['title']); $uri = JURI::getInstance(); // if (!$config['easyblog_image_size']) { $config['easyblog_image_size'] = 'original'; } // if (trim($item['image']) != '') { $image_object = json_decode($item['image']); $original_path = false; if ($config['easyblog_image_size'] == 'original') { $original_path = $image_object->url; } elseif ($config['easyblog_image_size'] == 'thumbnail') { $original_path = $image_object->thumbnail->url; } elseif ($config['easyblog_image_size'] == 'icon') { $original_path = $image_object->icon->url; } if ($original_path) { $IMG_SOURCE = substr($original_path, stripos($original_path, 'images/easyblog_images/')); } else { $IMG_SOURCE = ''; } } else { // set image to first in article content if (preg_match('/\\<img.*src=.*?\\>/', $item['text'])) { $imgStartPos = JString::strpos($item['text'], 'src="'); if ($imgStartPos) { $imgEndPos = JString::strpos($item['text'], '"', $imgStartPos + 5); } if ($imgStartPos > 0) { $IMG_SOURCE = JString::substr($item['text'], $imgStartPos + 5, $imgEndPos - ($imgStartPos + 5)); } } } // $full_size_img = $IMG_SOURCE; // if ($config['create_thumbs'] == 1 && $IMG_SOURCE != '') { // try to override standard image if (strpos($IMG_SOURCE, 'http://') == FALSE) { $img_file = NSP_GK5_Thumbs::createThumbnail($IMG_SOURCE, $config, false, false, '', $links); if (is_array($img_file)) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/' . $img_file[1]; } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } else { $IMG_SOURCE = ''; } } } elseif ($config['create_thumbs'] == 1) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'cache' . DS . 'default' . DS . 'default' . $config['module_id'] . '.png')) { $IMG_SOURCE = $uri->root() . 'modules/mod_news_pro_gk5/cache/default/default' . $config['module_id'] . '.png'; } } if ($only_url) { return $IMG_SOURCE; } else { // if ($IMG_SOURCE != '') { $class = ''; if (!$links) { $class = ' t' . $config['news_content_image_pos'] . ' f' . $config['news_content_image_float']; } $size = ''; $margins = ''; // if (!$links && $config['responsive_images'] == 1) { $class .= ' gkResponsive'; } // if (!$links) { if ($config['img_width'] != 0 && !$config['img_keep_aspect_ratio'] && $config['responsive_images'] == 0) { $size .= 'width:' . $config['img_width'] . 'px;'; } if ($config['img_height'] != 0 && !$config['img_keep_aspect_ratio'] && $config['responsive_images'] == 0) { $size .= 'height:' . $config['img_height'] . 'px;'; } if ($config['img_margin'] != '') { $margins = ' style="margin:' . $config['img_margin'] . ';"'; } } else { if ($config['links_img_width'] != 0 && !$config['img_keep_aspect_ratio'] && $config['responsive_images'] == 0) { $size .= 'width:' . $config['links_img_width'] . 'px;'; } if ($config['links_img_height'] != 0 && !$config['img_keep_aspect_ratio'] && $config['responsive_images'] == 0) { $size .= 'height:' . $config['links_img_height'] . 'px;'; } if ($config['links_img_margin'] != '') { $margins = ' style="margin:' . $config['links_img_margin'] . ';"'; } } // if ($config['news_image_link'] == 1) { if ($config['news_image_modal'] == 1) { return $config['news_content_image_pos'] == 'center' && !$links ? '<div class="center' . $class . '"><a href="' . $full_size_img . '" class="modal nspImageWrapper' . $class . '"' . $margins . ' target="' . $config['open_links_window'] . '"><img class="nspImage" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></a></div>' : '<a href="' . $full_size_img . '" class="modal nspImageWrapper' . $class . '"' . $margins . ' target="' . $config['open_links_window'] . '"><img class="nspImage' . $class . '" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></a>'; } else { $link = static::itemLink($item); return $config['news_content_image_pos'] == 'center' && !$links ? '<div class="center' . $class . '"><a href="' . $link . '" class="nspImageWrapper' . $class . '"' . $margins . ' target="' . $config['open_links_window'] . '"><img class="nspImage" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></a></div>' : '<a href="' . $link . '" class="nspImageWrapper' . $class . '"' . $margins . ' target="' . $config['open_links_window'] . '"><img class="nspImage' . $class . '" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></a>'; } } else { return $config['news_content_image_pos'] == 'center' && !$links ? '<div class="center' . $class . '"><span class="nspImageWrapper' . $class . '"' . $margins . '><img class="nspImage" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" ' . $size . ' /></span></div>' : '<span class="nspImageWrapper' . $class . '"' . $margins . '><img class="nspImage' . $class . '" src="' . $IMG_SOURCE . '" alt="' . htmlspecialchars($item['title']) . '" style="' . $size . '" /></span>'; } } else { return ''; } } } else { return ''; } }