public static function resizeImage($file, $folder, $width = 120, $height = 120, $iparams = array(), $loc_ext_name_com = null) { global $ext_name, $ext_name_com; $loc_ext_name_com = !empty($loc_ext_name_com) ? $loc_ext_name_com : $ext_name_com; $params = JComponentHelper::getParams($loc_ext_name_com); if (!isset($iparams['displace'])) { $iparams['displace'] = $params->get('displace', 0); } if (!isset($iparams['watermark'])) { $iparams['watermark'] = $params->get('watermark', 0); } if (!isset($iparams['halign'])) { $iparams['halign'] = $params->get('halign', 'center'); } if (!isset($iparams['valign'])) { $iparams['valign'] = $params->get('valign', 'middle'); } $iparams['watermark_type'] = $params->get('watermark_type', 0); $iparams['watermark_valign'] = $params->get('watermark_valign', 'middle'); $iparams['watermark_halign'] = $params->get('watermark_halign', 'center'); $iparams['background_type'] = $params->get('background_type', 'file'); natsort($iparams); $dst_file = basename($file); foreach ($iparams as $iparam) { $dst_file = JString::str_ireplace('/', '.', $iparam) . '-' . $dst_file; } if (!class_exists('SimpleImage')) { require dirname(__FILE__) . DS . '..' . DS . 'additional' . DS . 'simpleimage.php'; } /* if($width == 0) { $width = $params->get('thumb_width', 120); }*/ if ($height == 0) { $height = $params->get('thumb_height', 120); } $dst_path_segments = array('media', $loc_ext_name_com, 'images', $folder, 'w' . $width . 'x' . 'h' . $height); $dst_path = JPATH_ROOT; foreach ($dst_path_segments as $v) { $dst_path .= DS . $v; if (!JFolder::exists($dst_path)) { JFolder::create($dst_path); chmod($dst_path, 0777); } } $file != '' ? $dst_filename = $dst_path . DS . $dst_file : ($dst_filename = $dst_path . DS . 'no.jpg'); if (!JFile::exists($dst_filename)) { if ($file != '') { $src_filename = JPATH_ROOT . DS . 'media' . DS . $loc_ext_name_com . DS . 'images' . DS . $folder . DS . 'original' . DS . basename($file); } else { $src_filename = JPATH_ROOT . DS . 'media' . DS . $loc_ext_name_com . DS . 'images' . DS . $folder . DS . 'no.jpg'; } if (!JFile::exists($src_filename)) { $src_filename = JPATH_ROOT . DS . 'media' . DS . $loc_ext_name_com . DS . 'images' . DS . $folder . DS . 'no.jpg'; } $image = new SimpleImage($src_filename); if ($width == 0) { $ratio = $height / $image->get_height(); $width = $image->get_width() * $ratio; } if ($image->get_width() > $width || $image->get_height() > $height) { $ratio_in = $image->get_width() / $image->get_height(); if ($iparams['displace'] == 0) { $ratio_out = $width / $height; if ($ratio_in > $ratio_out) { $image->resize((int) $width * $ratio_in, $height); } else { $image->resize($width, $width / $ratio_in); } $x1 = 0; $y1 = 0; switch ($iparams['halign']) { case 'center': $x1 = round($image->get_width() / 2 - $width / 2); break; case 'right': $x1 = round($image->get_width() - $width); break; } switch ($iparams['valign']) { case 'middle': $y1 = round($image->get_height() / 2 - $height / 2); break; case 'bottom': $y1 = round($image->get_height() - $height); break; } $image->crop($x1, $y1, $x1 + $width, $y1 + $height); } else { if ($width / $ratio_in > $height) { $image->resize($height * $ratio_in, $height); } else { $image->resize($width, $width / $ratio_in); } } } if ($iparams['watermark'] == 1) { $watermark_image = $params->get('watermark_image', ''); if (file_exists(JPATH_ROOT . DS . $watermark_image) && is_file(JPATH_ROOT . DS . $watermark_image)) { $image->watermark(JPATH_ROOT . DS . $watermark_image, $iparams); } } $bg_file = $params->get('background_file', ''); $image->background($width, $height, $iparams, $bg_file, $params->get('background_color', 'ffffff')); //$image->best_fit($width, $height); if ($iparams['background_type'] == 'file' && (empty($bg_file) || !empty($bg_file) && !file_exists(JPATH_ROOT . DS . $file))) { $image->save($dst_filename, 'png'); } else { $image->save($dst_filename); } } return JURI::root() . str_replace(JPATH_ROOT . DS, '', $dst_filename); }