Esempio n. 1
0
 public function resizeImg($orig, $new, $new_width, $new_height, $ow, $oh)
 {
     require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'image.php';
     return OPCimage::resizeImg($orig, $new, $new_width, $new_height, $ow, $oh);
 }
Esempio n. 2
0
 public static function op_image_tag($image, $args = "", $resize = 1, $path_appendix = 'product', $thumb_width = 0, $thumb_height = 0, $retA = false)
 {
     $oi = $image;
     if (empty($image)) {
         $image = VmConfig::get('vm_themeurl', JURI::root() . 'components/com_virtuemart/') . 'assets/images/vmgeneral/' . VmConfig::get('no_image_set');
     }
     if (strpos($image, 'http') === 0) {
         // if the image starts with http
         $imga = array();
         $imga['width'] = $thumb_width;
         $imga['height'] = $thumb_height;
         $imga['iurl'] = $image;
     }
     if (!file_exists($image) || !is_file($image)) {
         $image = VmConfig::get('vm_themeurl', JURI::root() . 'components/com_virtuemart/') . 'assets/images/vmgeneral/' . VmConfig::get('no_image_set');
         $imga = array();
         $imga['width'] = $thumb_width;
         $imga['height'] = $thumb_height;
         $imga['iurl'] = $image;
     }
     $height = $width = 0;
     $ow = $thumb_width;
     $oh = $thumb_height;
     if ($image != "") {
         $fi = pathinfo($image);
         //
         // to resize we need to know if to keep height or width
         $arr = getimagesize($image);
         $width = $arr[0];
         $height = $arr[1];
         if (empty($thumb_width) && !empty($thumb_height)) {
             $rate = $height / $thumb_height;
             // 1.5
             $thumb_width = round($width / $rate);
             // if width<height do nothing
             //if ($width>$height && ())
         } else {
             if (empty($thumb_height)) {
                 $rate = $width / $thumb_width;
                 $thumb_height = round($height / $rate);
             } else {
                 if (empty($thumb_height) && empty($thumb_width)) {
                     $thumb_height = $height;
                     $thumb_width = $width;
                 }
             }
         }
         // check ratio:
         $r1 = round($thumb_height / $thumb_width, 3);
         $r2 = round($height / $width, 3);
         if ($r1 != $r2) {
             // the ratio got changed
             $thumb_height = $thumb_height * $r2;
             if ($thumb_height > $oh) {
                 // reverse
                 $thumb_height = $thumb_height / $r2;
                 $thumb_width = $thumb_width / $r2;
             }
             //$thumb_width = $thumb_width * $r2;
         }
         if (!empty($fi['extension'])) {
             $basename = str_replace('.' . $fi['extension'], '', $fi['basename']);
             $u = VmConfig::get('media_product_path');
             $u = str_replace('/', DS, $u);
             $filename = JPATH_SITE . DS . $u . $ow . 'x' . $oh . DS . $fi['basename'];
             $dirname = JPATH_SITE . DS . $u . $ow . 'x' . $oh;
             jimport('joomla.filesystem.file');
             if (file_exists($filename)) {
                 $arr = getimagesize($filename);
                 if ($arr === false) {
                     // we've got a corrupted image here
                     JFile::delete($filename);
                 }
             }
             if ($width > $thumb_width || $height > $thumb_height || !file_exists($filename)) {
                 if (!file_exists($dirname)) {
                     jimport('joomla.filesystem.folder');
                     jimport('joomla.filesystem.file');
                     if (@JFolder::create($dirname) === false) {
                         // we can't create a directory and we don't want to get into a loop
                         return "&nbsp;";
                     }
                     $x = ' ';
                     if (@JFile::write($dirname . DS . 'index.html', $x) === false) {
                         // we can't create a directory and we don't want to get into a loop
                         return "&nbsp;";
                     }
                 }
                 if (file_exists($dirname) && !file_exists($filename)) {
                     OPCimage::resizeImg($image, $filename, $thumb_width, $thumb_height, $width, $height);
                     $arr = @getimagesize($filename);
                     if ($arr === false) {
                         return array();
                     }
                     $width = $arr[0];
                     $height = $arr[1];
                 } else {
                     if (file_exists($dirname) && file_exists($filename)) {
                         $arr = @getimagesize($filename);
                         if ($arr === false) {
                             return array();
                         }
                         $width = $arr[0];
                         $height = $arr[1];
                     } else {
                         if (!empty($oi)) {
                             return OPCimage::op_image_tag("", $args, 0, 'product', $thumb_width, $thumb_height, $retA);
                         } else {
                             if ($retA === true) {
                                 return array();
                                 return "&nbsp;";
                             } else {
                             }
                         }
                     }
                 }
                 // we need to create it
                 // should be here:
                 //
             }
         }
     }
     if ($retA === true) {
         if (!file_exists($filename)) {
             return array();
         }
         $imga = array();
         $imga['width'] = $width;
         $imga['height'] = $height;
         $imga['iurl'] = OPCimage::path2url($filename);
         return $imga;
     } else {
         if (empty($url)) {
             return "&nbsp;";
         }
         return '<img src="' . $url . '" />';
     }
     //return vmCommonHTML::imageTag( $url, '', '', $height, $width, '', '', $args.' '.$border );
 }
Esempio n. 3
0
 function getImage($catId)
 {
     $db = JFactory::getDBO();
     $q = "select m.file_title,m.file_url\n\t\t\tfrom `#__virtuemart_medias` as m \n\t\t\tINNER JOIN #__virtuemart_category_medias as cat \n\t\t\tON m.virtuemart_media_id = cat.virtuemart_media_id \n\t\t\tWHERE cat.virtuemart_category_id = '" . $db->getEscaped($catId) . "'limit 1";
     $db->setQuery($q);
     $arr = $db->loadAssocList();
     $image = '';
     if ($arr[0]['file_url']) {
         $path = DS . "images" . DS . "com_opc_util_menu" . DS . "19_19";
         $abspath = JPATH_SITE . $path;
         jimport('joomla.filesystem.file');
         if (!JFolder::exists($abspath)) {
             JFolder::create($abspath);
         }
         $filename = JFile::makeSafe($arr[0]['file_title']);
         $filepath = $abspath . DS . $filename;
         $origFile = JPATH_ROOT . DS . $arr[0]['file_url'];
         list($width, $height, $type, $attr) = getimagesize($origFile);
         // resize image and copy to $filepath
         OPCimage::resizeImg($origFile, $filepath, 19, 19, $width, $height);
         $image = $path . DS . $filename;
     }
     return $image;
 }