Page 1 of 1

Cannot figure out how to use crop instead resiye function

Posted: Mon Mar 23, 2009 6:08 pm
by neddim
First off all, hello to everybody and I am glad that I have found forum like this. I am having problem with one part of my code. Indeed, this is a free script that I have found on the net for Joomla. And it is okay for now. My problem is, there is a function that resize image to the certain dimensions, but it doesnt crop it. I need to do the crop function and only to fit by with cause height is not important for me. It also crops image (make thumbs, but it stretch/squeeze image to needed dimensions, so it doesnt look okay and nice). I just need that function to simply crop image by width and by fixed height.
There is a code. If someone more experienced than me can make a look, I would be grateful.

Code: Select all

<?php
/**
* @version $Id: mod_article_thumbnails.php v2.07
* @package Joomla 1.0.12
* @by Cuong Kieu Nguyen
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/
 
/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
 
global $mosConfig_offset, $mosConfig_live_site, $mainframe;
 
if (!function_exists("atfn_thbimg_dsply")) {
  function atfn_thbimg_dsply ($thb_img, $at_thbimg_ctrl, $at_randimg, $imgs, $at_im_bdr, $at_im_ptn, $at_im_lf, $at_im_rt, $at_im_tp, $at_im_bm, $at_im_wh, $at_im_ht, $at_im_at, $at_mkthb_sfx, $at_im_path) {
    $dpl_img = atfn_randimg($at_randimg, $imgs);
    $class="";
    if ($at_im_ptn == 'center') {
      $at_im_ptn = '';
    }
    else {
      $at_im_ptn = 'float: ' . $at_im_ptn. '; ';
    }
    $extra =' border="' . $at_im_bdr . '" style="' . $at_im_ptn . 'margin-left: ' . $at_im_lf . 'em; margin-right: ' . $at_im_rt . 'em; margin-top: ' . $at_im_tp . 'em; margin-bottom: ' . $at_im_bm . 'em;" alt=""';
    if (preg_match_all("#http#s", $dpl_img, $remtimg, PREG_PATTERN_ORDER) > 0) {
      $img = $dpl_img;
      $thb_img = atfn_remt_resize($thumb_img, $img,$at_im_wh,$at_im_ht,$at_im_at,$extra);
    }
    else {
      $img = "/" . $at_im_path . "/" . $dpl_img;
      if ($at_thbimg_ctrl == 1) {
        $thb_img = atfn_mkthb($img, $at_im_wh, $at_im_ht, $image, $extra, $class, $at_im_at, $at_mkthb_sfx);
      }
      else {
        $thb_img = atfn_resize($thumb_img, $img,$at_im_wh,$at_im_ht,$at_im_at,$extra);
      }
    }
    if ($at_im_ptn == '') {
      $thb_img = '<center>' . $thb_img . '</center>';
    }
    return $thb_img ;
  }
}
 
if (!function_exists("atfn_remt_resize")) {
  function atfn_remt_resize ($thumb_img,$img_thumb_src,$img_at_im_wh,$img_at_im_ht,$img_thumb_at_im_at_ctrl,$img_thumb_extra) {
    $img_orgn_size = @getimagesize($img_thumb_src );
    if (is_array( $img_orgn_size )) {
      $img_orgn_size_wx = $img_orgn_size[0];
      $img_orgn_size_hy = $img_orgn_size[1];
      if ($img_thumb_at_im_at_ctrl==0) {
        $thumb_img = '<img src="' . $img_thumb_src . '" width="' . $img_at_im_wh . '" height="' . $img_at_im_ht . '"' . $img_thumb_extra . ' />';
      }
      else {
        if ($img_at_im_ht < $img_orgn_size_hy*$img_at_im_wh/$img_orgn_size_wx) {
          $thumb_img = '<img src="' . $img_thumb_src . '" width="' . $img_at_im_wh . '"' . $img_thumb_extra . ' />';
        }
        else {
          $thumb_img = '<img src="' . $img_thumb_src . '" height="' . $img_at_im_ht . '"' . $img_thumb_extra . ' />';
        }
      }
    }
    else {
      $thumb_img = '';
    }
    return $thumb_img;
  }
}
 
if (!function_exists("atfn_resize")) {
  function atfn_resize ($thumb_img,$img_thumb_src,$img_at_im_wh,$img_at_im_ht,$img_thumb_at_im_at_ctrl,$img_thumb_extra) {
    global $mosConfig_absolute_path, $mosConfig_live_site;
    $img_orgn_size = @getimagesize( $mosConfig_absolute_path.$img_thumb_src );
    if (is_array( $img_orgn_size )) {
      $img_orgn_size_wx = $img_orgn_size[0];
      $img_orgn_size_hy = $img_orgn_size[1];
      if ($img_thumb_at_im_at_ctrl==0) {
        $thumb_img = '<img src="' . $mosConfig_live_site . $img_thumb_src . '" width="' . $img_at_im_wh . '" height="' . $img_at_im_ht . '"' . $img_thumb_extra . ' />';
      }
      else {
        if ($img_at_im_ht < $img_orgn_size_hy*$img_at_im_wh/$img_orgn_size_wx) {
          $thumb_img = '<img src="' . $mosConfig_live_site . $img_thumb_src . '" width="' . $img_at_im_wh . '"' . $img_thumb_extra . ' />';
        }
        else {
          $thumb_img = '<img src="' . $mosConfig_live_site . $img_thumb_src . '" height="' . $img_at_im_ht . '"' . $img_thumb_extra . ' />';
        }
      }
    }
    else {
      $thumb_img = '';
    }
    return $thumb_img;
  }
}
 
if (!function_exists("atfn_mkthb")) {
  function atfn_mkthb($file, $wdth, $hgth, &$image, &$xtra, $class, $at_im_at, $at_mkthb_sfx){
    global $mosConfig_absolute_path, $mosConfig_live_site;
    if($class!='') $xtra .= ' class="'.$class.'"';
    $ext = substr(strrchr(basename($mosConfig_absolute_path.$file), '.'), 1);
    $thumb = str_replace('.'.$ext, $at_mkthb_sfx.'.'.$ext, $file);
    $image = '';
    $image_path = $mosConfig_absolute_path.$thumb;
    $image_site = $mosConfig_live_site.$thumb;
    $found = false;
    if (file_exists($image_path)) {
      $size = '';
      $wx = $hy = 0;
      if (function_exists( 'getimagesize' )) {
        $size = @getimagesize( $image_path );
        if (is_array( $size )) {
          $wx = $size[0];
          $hy = $size[1];
          $size = 'width="'.$wx.'" height="'.$hy.'"';
        }
      }
      if ($wx == $wdth && $hy == $hgth) {
        $found = true;
        $image= '<img src="'.$image_site.'" '.$size.$xtra.' />';
      }
    }
    if (!$found) {
      $size = '';
      $wx = $hy = 0;
      $size = @getimagesize( $mosConfig_absolute_path.$file );
      if (is_array( $size )) {
        $wx = $size[0];
        $hy = $size[1];
      }
      atfn_calsz($wx, $hy, $wdth, $hgth, $at_im_at);
      switch ($ext) {
        case 'jpg':
        case 'jpeg':
        case 'png':
          atfn_thumbit($mosConfig_absolute_path.$file,$image_path,$ext,$wdth,$hgth);
      $size = 'width="'.$wdth.'" height="'.$hgth.'"';
          $image= '<img  src="'.$image_site.'" '.$size.$xtra.' />';
          break;
    case 'gif':
          if (function_exists("imagegif")) {
        atfn_thumbit($mosConfig_absolute_path.$file,$image_path,$ext,$wdth,$hgth);
        $size = 'width="'.$wdth.'" height="'.$hgth.'"';
        $image= '<img src="'.$image_site.'" '.$size.$xtra.' />';
        break;
          } 
    default:
      $size = 'width="'.$wdth.'" height="'.$hgth.'"';
          $image= '<img src="'.$mosConfig_live_site.$file.'" '.$size.$xtra.' />';
          break;
      }
    }
    return $image;
  }
}
 
if (!function_exists("atfn_thumbit")) {
  function atfn_thumbit ($file, $thumb, $ext, &$new_width, &$new_height) {
    $img_info = getimagesize ( $file );
    $orig_width = $img_info[0];
    $orig_height = $img_info[1];
    if($orig_width<$new_width || $orig_height<$new_height){
      $new_width = $orig_width;
      $new_height = $orig_height;
    }
    switch ($ext) {
      case 'jpg':
      case 'jpeg':
        $im  = imagecreatefromjpeg($file);
        $tim = imagecreatetruecolor ($new_width, $new_height);
        atfn_ImageCopyResampleBicubic($tim, $im, 0,0,0,0, $new_width, $new_height, $orig_width, $orig_height);
        imagedestroy($im);
        imagejpeg($tim, $thumb, 75);
        imagedestroy($tim);
        break;
      case 'png':
        $im  = imagecreatefrompng($file);
        $tim = imagecreatetruecolor ($new_width, $new_height);
        atfn_ImageCopyResampleBicubic($tim, $im, 0,0,0,0, $new_width, $new_height, $orig_width, $orig_height);
        imagedestroy($im);
        imagepng($tim, $thumb, 75);
        imagedestroy($tim);
        break;
      case 'gif':
    if (function_exists("imagegif")) {
      $im  = imagecreatefromgif($file);
      $tim = imagecreatetruecolor ($new_width, $new_height);
      atfn_ImageCopyResampleBicubic($tim, $im, 0,0,0,0, $new_width, $new_height, $orig_width, $orig_height);
      imagedestroy($im);
      imagegif($tim, $thumb, 75);
      imagedestroy($tim);
        }
        break;
      default:
        break;
    }
  }
}
 
if (!function_exists("atfn_ImageCopyResampleBicubic")) {
  function atfn_ImageCopyResampleBicubic (&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) {
    if($dst_w==$src_w && $dst_h==$src_h){
      $dst_img = $src_img;
      return;
    }
    ImagePaletteCopy ($dst_img, $src_img);
    $rX = $src_w / $dst_w;
    $rY = $src_h / $dst_h;
    $w = 0;
    for ($y = $dst_y; $y < $dst_h; $y++) {
      $ow = $w; $w = round(($y + 1) * $rY);
      $t = 0;
      for ($x = $dst_x; $x < $dst_w; $x++) {
        $r = $g = $b = 0; $a = 0;
        $ot = $t; $t = round(($x + 1) * $rX);
        for ($u = 0; $u < ($w - $ow); $u++) {
          for ($p = 0; $p < ($t - $ot); $p++) {
            $c = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $ot + $p, $ow + $u));
            $r += $c['red'];
            $g += $c['green'];
            $b += $c['blue'];
            $a++;
          }
        }
    if(!$a) $a = 1;
        ImageSetPixel ($dst_img, $x, $y, ImageColorClosest ($dst_img, $r / $a, $g / $a, $b / $a));
      }
    }
  }  
}
 
if (!function_exists("atfn_calsz")) {
  function atfn_calsz($srcx, $srcy, &$forcedwidth, &$forcedheight, $at_im_at) {
    if ($forcedwidth > $srcx)  $forcedwidth = $srcx;
    if ($forcedheight > $srcy) $forcedheight = $srcy;
    if ( $forcedwidth <=0 && $forcedheight > 0) {
      $forcedwidth = round(($forcedheight * $srcx) / $srcy);
    }
    else if ( $forcedheight <=0 && $forcedwidth > 0) {
      $forcedheight = round(($forcedwidth * $srcy) / $srcx);
    }
    else if ( $forcedwidth/$srcx>1 && $forcedheight/$srcy>1) {
      $forcedwidth = $srcx;
      $forcedheight = $srcy;
    }
    else if ( $forcedwidth/$srcx<1 && $at_im_at) {
      $forcedheight = round(($forcedheight * $forcedwidth) /$srcx);
    }
    else if ( $forcedheight/$srcy<1 && $at_im_at) {
      $forcedwidth = round(($forcedheight * $forcedwidth) /$srcy);
    }
  }
}
 
if (!function_exists("atfn_txtlm")) {
  function atfn_txtlm($txt,$at_ar_lm) {
    $len=strlen($txt);
    if($len <= $at_ar_lm)
      return $txt;
    else {
      $txt = substr($txt,0,$at_ar_lm);
      $pos = strrpos($txt," ");
      if($pos >0) {
        $txt = substr($txt,0,$pos);
    if (($tpos =strrpos($txt,"<")) >  strrpos($txt,">") && $tpos>0) {
          $txt = substr($txt,0,$tpos-1);
    }
      }
      return $txt . "...";
    }
  }
}
 
if (!function_exists("atfn_randimg")) {
  function atfn_randimg($at_randimg, $images_list) {
    if ( $at_randimg == 1 ) {
      $rowimageslist = explode("\n",$images_list);
      $introimagenumber = rand(0,count($rowimageslist)-1);
      $images_list = strtok($rowimageslist[$introimagenumber],"|\r\n");
    } 
    else {
      $images_list = strtok($images_list,"|\r\n");;
    }
    return $images_list;
  }
}
 
if (!function_exists("intro_display")) {
  function intro_display($at_itr_css, $at_itr_cl, $intro_text) {
    if ( $at_itr_cl==1 ) {
      echo '<div class="' . $at_itr_css . '">' . $intro_text . '</div>';
    } 
  }
}
 
if (!function_exists("atfn_getid")) {
  function atfn_getid ($id, $option="com_content") {
    global $database, $Itemid;
    $_Itemid = "";
    // Content Category Link
    if ($_Itemid == "") {
      $database->setQuery( "SELECT catid "
              ."FROM #__content "
              ."WHERE id='$id'" );
      $current_catid = $database->loadResult();
      $database->setQuery( "SELECT name "
              ."FROM #__categories "
              ."WHERE id='$current_catid'" );
      $current_catname = $database->loadResult();
      $database->setQuery( "SELECT id "
              ."FROM #__menu "
              ."WHERE type='content_blog_category' AND name='$current_catname'" );
      $_Itemid = $database->loadResult();
    }
    // Content Item Link
    if ($_Itemid == "") {
      $database->setQuery( "SELECT id "
              ."FROM #__menu "
              ."WHERE type='content_item_link' AND published='1' AND link='index.php?option=$option&task=view&id=$id'" );
      $_Itemid = $database->loadResult();
    }
    // Typed Content Link
    if ($_Itemid == "") {
      $database->setQuery( "SELECT id "
              ."FROM #__menu "
              ."WHERE type='content_typed' AND published='1' AND link='index.php?option=$option&task=view&id=$id'" );
      $_Itemid = $database->loadResult();
    }
    // Content Section List
    if ($_Itemid == "") {
      $database->setQuery( "SELECT m.id "
              ."FROM #__content AS i "
              ."LEFT JOIN #__sections AS s ON i.sectionid=s.id "
              ."LEFT JOIN #__menu AS m ON m.componentid=s.id "
              ."WHERE m.type='content_section' AND m.published='1' AND i.id='$id'" );
      $_Itemid = $database->loadResult();
    }
    // Content Category List
    if ($_Itemid == "") {
      $database->setQuery( "SELECT sectionid, catid "
              ."FROM #__content WHERE id='$id'" );
      $row = null;
      $database->loadObject( $row );
      $database->setQuery( "SELECT id "
              ."FROM #__menu "
              ."WHERE type='content_category' AND published='1' AND link='index.php?option=$option&task=category&sectionid=$row->sectionid&id=$row->catid'");
      $_Itemid = $database->loadResult();
    }
    // Content Section Blog (specific)
    if ($_Itemid == "") {
      $database->setQuery( "SELECT m.id "
              ."FROM #__content AS i "
              ."LEFT JOIN #__sections AS s ON i.sectionid=s.id "
              ."LEFT JOIN #__menu AS m ON m.componentid=s.id "
              ."WHERE m.type='content_blog_section' AND m.published='1' AND i.id='$id'" );
      $_Itemid = $database->loadResult();
    }
    // Content Category Blog (specific)
    if ($_Itemid == "") {
      $database->setQuery( "SELECT m.id "
              ."FROM #__content AS i "
              ."LEFT JOIN #__categories AS c ON i.catid=c.id "
              ."LEFT JOIN #__menu AS m ON m.componentid=c.id "
              ."WHERE m.type='content_blog_category' AND m.published='1' AND i.id='$id'" );
      $_Itemid = $database->loadResult();
    }
    // Content Section Blog (global)
    if ($_Itemid == "") {
      // Search in global blog section
      $database->setQuery( "SELECT id "
              ."FROM #__menu "
              ."WHERE type='content_blog_section' AND published='1' AND componentid='0'" );
      $_Itemid = $database->loadResult();
    }
    // Content Category Blog (global)
    if ($_Itemid == "") {
      $database->setQuery( "SELECT id "
              ."FROM #__menu "
              ."WHERE type='content_blog_category' AND published='1' AND componentid='0'" );
      $_Itemid = $database->loadResult();
    }
    if ($_Itemid != "") {
      return $_Itemid;
    } 
    else {
      return $Itemid;
    }
  }
}
 
$at_mn_tb = $params->get( 'at_mn_tb', 'at_main_table' );
$at_el_tb = $params->get( 'at_el_tb', 'at_element_table' );
$at_im_tb = $params->get( 'at_im_tb', 'at_img_table' );
$at_ttl_css = $params->get( 'at_ttl_css', 'at_title' ) ;
$at_itr_css = $params->get( 'at_itr_css', 'at_intro' ) ;
$at_dt_css = $params->get( 'at_dt_css', 'at_date' );
$at_fltxt_css = $params->get( 'at_fltxt_css', 'at_readmore' ) ;
 
$at_im_dspl = intval( $params->get( 'at_im_dspl', 0 ) );
$at_embed = intval( $params->get( 'at_embed', 0 ) );
$at_im_at = intval( $params->get( 'at_im_at', 0 ) );
$at_im_ptn = intval( $params->get( 'at_im_ptn', 1 ) );
$at_randimg = intval( $params->get( 'at_randimg', 1 ) );
$at_im_lf = $params->get( 'at_im_lf', 0 );
$at_im_rt = $params->get( 'at_im_rt', 0.2 );
$at_im_tp = $params->get( 'at_im_tp', 0.1 );
$at_im_bm = $params->get( 'at_im_bm', 0.1 );
$at_im_bdr = intval( $params->get( 'at_im_bdr', 1 ) );
$at_im_wh = intval( $params->get( 'at_im_wh' ) );
$at_im_ht = intval( $params->get( 'at_im_ht' ) );
 
$at_im_path = $params->get( 'at_im_path', 'images/stories' );
$at_thbimg_ctrl = $params->get( 'at_thbimg_ctrl', 0 );
$at_mkthb_sfx = $params->get( 'at_mkthb_sfx', '_thumb' );
$at_cols = intval( $params->get( 'at_cols', 1 ) );
$at_dt_cl = intval( $params->get( 'at_dt_cl', 0 ) );
$at_itr_cl = intval( $params->get( 'at_itr_cl', 0 ) );
$at_ar_lm = intval( $params->get( 'at_ar_lm', 0 ) );
$at_fltxt_cl = $params->get( 'at_fltxt_cl', 0 );
$at_fltxt = $params->get( 'at_fltxt', '' ) ;
$at_fltxt_pn = intval( $params->get( 'at_fltxt_pn', 2 ) );
$at_lt_dn = intval( $params->get( 'at_lt_dn', 1 ) );
$at_stptg = intval( $params->get( 'at_stptg', 0 ) );
$at_pn = intval( $params->get( 'at_pn', 1 ) );
$at_ttl_pn = intval( $params->get( 'at_ttl_pn', 0 ) );
$at_ttl_lk = intval( $params->get( 'at_ttl_lk', 1 ) ); 
 
$at_ctnt_ctrl = intval( $params->get( 'at_ctnt_ctrl', 0 ) );
$at_pop = intval( $params->get( 'at_pop', 0 ) );
$at_pop_days = intval( $params->get( 'at_pop_days', 0 ) );
$at_sctns = $params->get( 'at_sctns', -1 ) ;
$at_cats = $params->get( 'at_cats', -1 ) ;
$at_items = $params->get( 'at_items', -1 ) ;
$at_nums = intval( $params->get( 'at_nums', 5 ) );
$at_skps = intval( $params->get( 'at_skps', 0 ) );
$at_randat = intval( $params->get( 'at_randat', 1 ) );
$at_dspl_no = intval( $params->get( 'at_dspl_no', 1 ) );
 
$allowed_tags =  "<br><i>";
$at_ttl_css = ' class="' . $at_ttl_css . '" ';
$at_im_tb = ' class="' . $at_im_tb . '" ';
$at_fltxt_css = ' class="' . $at_fltxt_css . '" ';
 
if ( $at_dspl_no > $at_nums ) {
  $at_dspl_no = $at_nums;
}
 
if ($at_im_ptn == 1) {
  $at_im_ptn = 'left';
}
elseif ($at_im_ptn == 0) {
  $at_im_ptn = 'right';
}
elseif ($at_im_ptn == 2) {
  $at_im_ptn = 'center';
}
 
if ($at_fltxt_pn == 0) {
  $at_fltxt_pn = 'left';
}
elseif ($at_fltxt_pn == 2) {
  $at_fltxt_pn = 'right';
}
elseif ($at_fltxt_pn == 1) {
  $at_fltxt_pn = 'center';
}
 
if ($at_pn == 0) {
  $at_pn = 'top';
}
elseif ($at_pn == 1) {
  $at_pn = 'middle';
}
elseif ($at_pn == 2) {
  $at_pn = 'bottom';
}
 
if ($at_ctnt_ctrl==2) {
  $at_qry_cat = '';
  $at_qry_im = '';
  $at_qry_whr = "\n WHERE a.state = '1'";
  $at_qry_pbl = '';
}
elseif ($at_ctnt_ctrl==1) {
  $at_qry_cat = '';
  $at_qry_im = '';
  $at_qry_whr = "\n WHERE ( a.state = 1 AND a.sectionid = 0 )";
  $at_qry_pbl = '';
}
else {
  $at_qry_cat = "\n INNER JOIN #__categories AS cc ON cc.id = a.catid";
  $at_qry_im = ", cc.image";
  $at_qry_whr = "\n WHERE a.state = '1'";
  $at_qry_pbl = "\n AND published = '1'";
}
 
$now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 );
if (( $at_pop_days > 0 ) && ((time()+$mosConfig_offset*60*60-60*60*24*$at_pop_days) > 0) ){
  $pop_time = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60-60*60*24*$at_pop_days );
} else {
  $pop_time = '0000-00-00 00:00:00';
}
 
// most popular query added here
if ($at_pop==1) {
  if (($at_sctns == -1) && ($at_cats == -1)) {
    // query records
    $query = "SELECT a.*" . $at_qry_im . " AS image"
    . "\n FROM #__content AS a"
    . $at_qry_cat
    . $at_qry_whr
    . "\n AND ( publish_up = '0000-00-00 00:00:00' OR ( '$pop_time' <= publish_up AND publish_up <= '$now')  )"
    . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
    . $at_qry_pbl
    . "\n ORDER BY a.hits DESC"
    . "\nlimit $at_skps," . $at_nums
    ;
    $database->setQuery( $query );
    $rows = $database->loadObjectList();
  }
  else {
    $where  = " AND (";
    if ($at_sctns != "") $where .= "sectionid IN (". $at_sctns. ") ";
    if ($at_sctns != "" && $at_cats != "" ) $where .= " OR ";
    if ($at_sctns != "" && $at_cats != "" ) $where .= "cc.id IN (". $at_cats. ")";
    $where .= ") ";
    $query = "SELECT a.*" . $at_qry_im . " AS image"
    . "\n FROM #__content AS a"
    . "\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
    . $at_qry_whr
    . $where 
    . "\n AND ( publish_up = '0000-00-00 00:00:00' OR ( '$pop_time' <= publish_up AND publish_up <= '$now')  )"
    . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
    . $at_qry_pbl
    . "\n ORDER BY a.hits DESC"
    . "\nlimit $at_skps," . $at_nums
    ;
    $database->setQuery( $query );
    $rows = $database->loadObjectList();
  }
}
// most popular query end
 
// default query
 
else {
  if (($at_sctns == -1) && ($at_cats == -1) && ($at_items == -1)) {
    // query records
    $query = "SELECT a.*" . $at_qry_im . " AS image"
    . "\n FROM #__content AS a"
    . $at_qry_cat
    . $at_qry_whr
    . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now'  )"
    . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
    . $at_qry_pbl
    . "\n ORDER BY publish_up DESC"
    . "\nlimit $at_skps," . $at_nums
    ;
    $database->setQuery( $query );
    $rows = $database->loadObjectList();
  }
  elseif ($at_items != -1) {
        $query = "SELECT a.*" . $at_qry_im . " AS image"
    . "\n FROM #__content AS a"
    . $at_qry_cat
    . $at_qry_whr
    . "\n AND ( a.id IN (". $at_items .") ) "
    . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now'  )"
    . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
    . $at_qry_pbl
    . "\n ORDER BY publish_up DESC"
    . "\nlimit $at_skps," . $at_nums
    ;
 
    $database->setQuery( $query );
    $rows = $database->loadObjectList();
  }
  else {
    $where  = " AND (";
    if ($at_sctns != "") $where .= "sectionid IN (". $at_sctns. ") ";
    if ($at_sctns != "" && $at_cats != "" ) $where .= " OR ";
    if ($at_sctns != "" && $at_cats != "" ) $where .= "cc.id IN (". $at_cats. ")";
    $where .= ") ";
    // query records
    $query = "SELECT a.*" . $at_qry_im . " AS image"
    . "\n FROM #__content AS a"
    . "\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
    . $at_qry_whr
    . $where 
    . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now'  )"
    . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
    . $at_qry_pbl
    . "\n ORDER BY publish_up DESC"
    . "\nlimit $at_skps," . $at_nums
    ;
 
    $database->setQuery( $query );
    $rows = $database->loadObjectList();
  }
}
// default query end
 
echo $database->getErrorMsg();
 
// Output
$col = 0;
$pwidth = intval(100/$at_cols);
$rc = count($rows);
for ( $r = 0; $r < $rc; $r++) {
  preg_match_all("#<img(.*)>#i", $rows[$r]->introtext . $rows[$r]->fulltext, $txtimg);
  if (!empty($txtimg[0])) {
    foreach ($txtimg[0] as $txtimgel) {
      $rows[$r]->introtext = str_replace($txtimgel,"",$rows[$r]->introtext);
      if (strstr($txtimgel, $at_im_path)) {
        if (strstr($txtimgel, 'src="/')) {
          preg_match_all("#src=\"\/" . addslashes($at_im_path) . "\/([\:\-\/\_A-Za-z0-9\.]+)\"#",$txtimgel,$txtimgelsr);
        }
        else {
          preg_match_all("#src=\"" . addslashes($at_im_path) . "\/([\:\-\/\_A-Za-z0-9\.]+)\"#",$txtimgel,$txtimgelsr);
        }
        if (!empty($rows[$r]->images)) {
          $rows[$r]->images = $txtimgelsr[1][0] . "\n" . $rows[$r]->images;
        }
        else {
          $rows[$r]->images = $txtimgelsr[1][0];
        }
      } 
      elseif (preg_match_all("#http#",$txtimgel,$txtimelsr,PREG_PATTERN_ORDER) > 0) {
        preg_match_all("#src=\"([\-\/\_A-Za-z0-9\.\:]+)\"#",$txtimgel,$txtimgelsr);
        if (!empty($rows[$r]->images)) {
          $rows[$r]->images = $txtimgelsr[1][0] . "\n" . $rows[$r]->images;
        }
        else {
          $rows[$r]->images = $txtimgelsr[1][0];
        }
      }
    }
  }
  $rows[$r]->introtext= preg_replace("/{[^}]*}/","",$rows[$r]->introtext);
  $rows[$r]->itemid =  atfn_getid($rows[$r]->id);
  if($at_stptg == 1) {
    $rows[$r]->introtext = strip_tags($rows[$r]->introtext,$allowed_tags);
  }
  if($at_ar_lm > 0) {
    $rows[$r]->introtext = atfn_txtlm($rows[$r]->introtext,$at_ar_lm);
  }
}
 
if ($at_randat == 1) {
  shuffle($rows);
}
 
$at_el_suffix = 1;
$articlecount = 1;
 
?>
<link rel="stylesheet" type="text/css" href="modules/mod_article_thumbnails/at.css" />
<?php
 
// start display articles
if ($at_embed == 1 && $at_im_dspl != 1) {
  echo '<table  class="' . $at_mn_tb . '">';
  foreach ( $rows as $row ) {
    $at_lk = ' href="'. sefRelToAbs( 'index.php?option=com_content&task=view&id=' . $row->id . '&Itemid=' . $row->itemid ) .'">';
    if ($col==0) {  
      echo '<tr>';
    }
    echo '<td width="' . $pwidth . '%" valign="' . $at_pn . '"><table class="' . $at_el_tb . $at_el_suffix . '"><tr><td valign="top"  width="100%">';
    if ($at_ttl_lk == 1) {
      echo '<div ' . $at_ttl_css . '><a ' . $at_ttl_css . $at_lk .  $row->title . '</a></div>';
    } 
    else {
      echo '<div ' . $at_ttl_css . '>'.  $row->title . '</div>';
    }
    if ($at_dt_cl==1) {
      echo '<div class="' . $at_dt_css . '">' . mosFormatDate( $row->created ) . '</div>';
    }
    echo '</td></tr><tr><td valign="top" height="100%"><a ' . $at_im_tb . $at_lk;
    if ($row->images != "") {
      echo atfn_thbimg_dsply($thb_img, $at_thbimg_ctrl, $at_randimg, $row->images, $at_im_bdr, $at_im_ptn, $at_im_lf, $at_im_rt, $at_im_tp, $at_im_bm, $at_im_wh, $at_im_ht, $at_im_at, $at_mkthb_sfx, $at_im_path);
    }
    echo '</a>';
    intro_display($at_itr_css, $at_itr_cl, $row->introtext);
    if ($at_fltxt_cl==1) {
      echo '<div align="' . $at_fltxt_pn . '"><a ' . $at_fltxt_css . $at_lk . $at_fltxt . '</a></div>';
    }
    echo "</td></tr></table></td>";
    $col = ($col + 1) % $at_cols;
    if ($col ==0 ) echo "</tr>";
    if ( ($at_el_suffix=='1') && ($at_cols%2==1) ) {
      $at_el_suffix = '2';
    }
    elseif ( ($at_el_suffix=='2') && ($at_cols%2==1) ) {
      $at_el_suffix = '1';
    }
    if ( ($at_el_suffix=='1') && ($at_cols%2==0) ) {
      if ($articlecount%$at_cols==0) {
        $at_el_suffix = '1';
      }
      else {
        $at_el_suffix = '2';
      }
    }
    elseif ( ($at_el_suffix=='2') && ($at_cols%2==0) ) {
      if ($articlecount%$at_cols==0) {
        $at_el_suffix = '2';
      }
      else {
        $at_el_suffix = '1';
      }
    }
    $articlecount++;
    if ( $articlecount > $at_dspl_no ) {
      break 1;
    }
  }
  if ($col !=0) echo "</tr>";
  echo '</table>';
} 
else if ($at_lt_dn == 0) {
  echo '<table  class="' . $at_mn_tb . '">';
  foreach ( $rows as $row ) {
    $at_lk = ' href="'. sefRelToAbs( 'index.php?option=com_content&task=view&id=' . $row->id . '&Itemid=' . $row->itemid ) .'">';
    if ($col==0)    echo '<tr>';
    echo '<td width="' . $pwidth . '%" valign="' . $at_pn . '"><table class="' . $at_el_tb . $at_el_suffix . '"><tr>';
    if (($at_im_dspl != 1) && ($at_im_ptn == 'left')) {
      echo '<td valign="top"><a ' . $at_im_tb . $at_lk;
      if ($row->images != "") {     
        echo atfn_thbimg_dsply($thb_img, $at_thbimg_ctrl, $at_randimg, $row->images, $at_im_bdr, $at_im_ptn, $at_im_lf, $at_im_rt, $at_im_tp, $at_im_bm, $at_im_wh, $at_im_ht, $at_im_at, $at_mkthb_sfx, $at_im_path);
      } 
      echo '</a></td>';
    }
    echo '<td valign="top" width=100%>';
    if ($at_ttl_lk == 1) {
      echo '<div ' . $at_ttl_css . '><a ' . $at_ttl_css . $at_lk .  $row->title . '</a></div>';
    } 
    else {
      echo '<div ' . $at_ttl_css . '>'.  $row->title . '</div>';
    }
    if ($at_dt_cl==1) {
      echo '<div class="' . $at_dt_css . '">' . mosFormatDate( $row->created ) . '</div>';
    }
    intro_display($at_itr_css, $at_itr_cl, $row->introtext);
    echo "</td>";
    if (($at_im_dspl != 1) && ($at_im_ptn == 'right')) {
      echo '<td valign="top"><a ' . $at_im_tb . $at_lk;
      if ($row->images != "") {     
        echo atfn_thbimg_dsply($thb_img, $at_thbimg_ctrl, $at_randimg, $row->images, $at_im_bdr, $at_im_ptn, $at_im_lf, $at_im_rt, $at_im_tp, $at_im_bm, $at_im_wh, $at_im_ht, $at_im_at, $at_mkthb_sfx, $at_im_path);
      } 
      echo '</a></td>';
    }
    if ($at_fltxt_cl==1) {
      echo '</tr><tr><td colspan="2"><div align="' . $at_fltxt_pn . '"><a ' . $at_fltxt_css . $at_lk . $at_fltxt . '</a></div><td>';
    }
    echo "</tr></table></td>";
    $col = ($col + 1) % $at_cols;
    if ($col ==0 ) echo "</tr>";
    if ( ($at_el_suffix=='1') && ($at_cols%2==1) ) {
      $at_el_suffix = '2';
    }
    elseif ( ($at_el_suffix=='2') && ($at_cols%2==1) ) {
      $at_el_suffix = '1';
    }
    if ( ($at_el_suffix=='1') && ($at_cols%2==0) ) {
      if ($articlecount%$at_cols==0) {
        $at_el_suffix = '1';
      }
      else {
        $at_el_suffix = '2';
      }
    }
    elseif ( ($at_el_suffix=='2') && ($at_cols%2==0) ) {
      if ($articlecount%$at_cols==0) {
        $at_el_suffix = '2';
      }
      else {
        $at_el_suffix = '1';
      }
    }
    $articlecount++;
    if ( $articlecount > $at_dspl_no ) {
      break 1;
    }
  }
  if ($col !=0) echo "</tr>";
  echo '</table>';
} 
else {
  echo '<table  class="' . $at_mn_tb . '">';
  foreach ( $rows as $row ) {
    $at_lk = ' href="'. sefRelToAbs( 'index.php?option=com_content&task=view&id=' . $row->id . '&Itemid=' . $row->itemid ) .'">';
    if ($col==0)    echo '<tr>';
    echo '<td width="' . $pwidth . '%" valign="' . $at_pn . '"><table class="' . $at_el_tb . $at_el_suffix . '">';
    if ($at_ttl_pn == 0) {
      echo '<tr><td valign="top"  width=100%>';
      if ($at_ttl_lk == 1) {
        echo '<div ' . $at_ttl_css . '><a ' . $at_ttl_css . $at_lk .  $row->title . '</a></div>';
      } 
      else {
        echo '<div ' . $at_ttl_css . '>'.  $row->title . '</div>';
      }
      if ($at_dt_cl==1) {
        echo '<div class="' . $at_dt_css . '">' . mosFormatDate( $row->created ) . '</div>';
      }
      echo '</td></tr>';
    }
    echo  '<tr ><td valign="top"><a ' . $at_im_tb . $at_lk;
    if ($row->images != "") {       
      echo atfn_thbimg_dsply($thb_img, $at_thbimg_ctrl, $at_randimg, $row->images, $at_im_bdr, $at_im_ptn, $at_im_lf, $at_im_rt, $at_im_tp, $at_im_bm, $at_im_wh, $at_im_ht, $at_im_at, $at_mkthb_sfx, $at_im_path);
    }
    echo '</a></td></tr>';
    if ($at_ttl_pn == 1) {
      echo '<tr><td valign="top">';
      if ($at_ttl_lk == 1) {
        echo '<div ' . $at_ttl_css . '><a ' . $at_ttl_css . $at_lk .  $row->title . '</a></div>';
      } 
      else {
        echo '<div ' . $at_ttl_css . '>'.  $row->title . '</div>';
      }
      if ($at_dt_cl==1) {
        echo '<div class="' . $at_dt_css . '">' . mosFormatDate( $row->created ) . '</div>';
      } 
      echo '</td></tr>';
    }
    echo '<tr ><td valign="top" height="100%">';
    intro_display($at_itr_css, $at_itr_cl, $row->introtext);
    if ($at_fltxt_cl==1) {
      echo '<div align="' . $at_fltxt_pn . '"><a ' . $at_fltxt_css . $at_lk . $at_fltxt . '</a></div>';
    }
    echo "</td></tr></table></td>";
    $col = ($col + 1) % $at_cols;
    if ($col ==0 ) echo "</tr>";
    if ( ($at_el_suffix=='1') && ($at_cols%2==1) ) {
      $at_el_suffix = '2';
    }
    elseif ( ($at_el_suffix=='2') && ($at_cols%2==1) ) {
      $at_el_suffix = '1';
    }
    if ( ($at_el_suffix=='1') && ($at_cols%2==0) ) {
      if ($articlecount%$at_cols==0) {
        $at_el_suffix = '1';
      }
      else {
        $at_el_suffix = '2';
      }
    }
    elseif ( ($at_el_suffix=='2') && ($at_cols%2==0) ) {
      if ($articlecount%$at_cols==0) {
        $at_el_suffix = '2';
      }
      else {
        $at_el_suffix = '1';
      }
    }
    $articlecount++;
    if ( $articlecount > $at_dspl_no ) {
      break 1;
    }
  }
  if ($col !=0) echo "</tr>";
  echo '</table>';
}
?>
 

Re: Cannot figure out how to use crop instead resiye function

Posted: Wed Apr 01, 2009 7:24 am
by jaoudestudios
No one is going to go through pages and pages of code for you. If you want help I suggest you specify a line or a couple of lines where you think your issue is and state the problem you are having.

For image stuff i use http://www.forum.jaoudestudios.com/view ... f=13&t=183.

It is easy and simple.