Ejemplo n.º 1
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 );
 }
Ejemplo n.º 2
0
 function path2url($path)
 {
     require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'image.php';
     return OPCimage::path2url($path);
 }