get_height() public method

Get the current height
public get_height ( ) : integer
return integer
Beispiel #1
0
 /**
  * Verify and validate the extension of the uploaded file.
  *
  * @param string $name
  * @param string $type
  * @return boolean
  */
 public function validateSponsorImage($name, $tmpName, $type)
 {
     $allowedExtensions = array("gif", "jpeg", "jpg", "png", "pdf", "GIF", "JPEG", "JPG", "PNG", "PDF");
     $temp = explode(".", $name);
     $extension = end($temp);
     if (($type === "image/gif" || $type === "image/jpeg" || $type === "image/jpg" || $type === "image/pjpeg" || $type === "image/x-png" || $type === "image/png" || $type === "application/pdf") && in_array($extension, $allowedExtensions)) {
         $img = new SimpleImage($tmpName);
         $img->fit_to_width(360);
         $img->invert();
         $img->crop(0, ($img->get_height() - 190) / 2, 360, ($img->get_height() - 190) / 2 + 190);
         $img->invert();
         $img->save("_temp/_img.png");
         return true;
     } else {
         return false;
     }
 }
 function resizeImage($source_image, $target_image, $width = 0, $height = 0, $best_fit = false)
 {
     $SimpleImage = new SimpleImage($source_image);
     if ($best_fit) {
         $SimpleImage->best_fit($width, $height)->save($target_image, 100);
     } else {
         if (!$width && !$height) {
             $SimpleImage->save($target_image);
         } elseif ($SimpleImage->get_width() >= $width) {
             $SimpleImage->fit_to_width($width)->crop(0, 0, $width, $SimpleImage->get_height() > $height ? $height : $SimpleImage->get_height())->save($target_image);
         } elseif ($SimpleImage->get_height() >= $height) {
             $SimpleImage->fit_to_width($height)->crop(0, 0, $SimpleImage->get_width() > $width ? $width : $SimpleImage->get_width(), $height)->save($target_image);
         } else {
             $SimpleImage->best_fit($width, $height)->save($target_image);
         }
     }
 }
Beispiel #3
0
 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);
 }