Image verkleinert ausgeben(Resize)

Vileicht so

PHP:
function imageresize($var,$width,$height) 
{
   preg_match_all('#\[ img\](.+)\[ /img\]#U', $var, $matches); 
   $search = array('[ img]','[ /img]');  
   $replace = array('','');
   for($i=0;$i <= count($matches);$i++)
   {
      
      $imgsize = getimagesize($matches[1][$i]);
      if($imgsize[0] < $width && $imgsize[1] < $height) 
	  {
	     $image =  '<img src="'.$matches[1][$i].'" width="'.$imgsize[0].'" wanda="'.count($matches).'">';   
	  }
	  else if($imgsize[0] > $width && $imgsize[1] < $height)
	  {
	     $image =  '<img src="'.$matches[1][$i].'" width="'.$width.'">';
	  } 
	  else if($imgsize[0] < $width && $imgsize[1] > $height)
	  {
	     $image =  '<img src="'.$matches[1][$i].'" height="'.$height.'">';
	  } 
      else if($imgsize[0] > $width && $imgsize[1] > $height)
	  {
	     $image =  '<img src="'.$matches[1][$i].'" height="'.$height.'" width="'.$width.'">';
	  }
	  $retrun .= preg_replace('#\[ img\](.+)\[ /img\]#U', $image, $var); 
	}
	return $return;
	
}
Aber dann wird garnichts ausgegebn :-
 
So, ich bin wieder ein schritt weiter...

Jetzt wird alles einfach doppelt und dreifach ausgegeben :eek:

PHP:
function imageresize($var,$width,$height) 
{
   preg_match_all('#\[ img\](.+)\[ /img\]#U', $var, $matches); 
   $search = array('[ img]','[ /img]');  
   $replace = array('','');
   for($i=0;$i <= count($matches);$i++)
   {
      
      $imgsize = getimagesize($matches[1][$i]);
      if($imgsize[0] < $width && $imgsize[1] < $height) 
	  {
	     $image =  '<img src="'.$matches[1][$i].'" width="'.$imgsize[0].'" wanda="'.count($matches).'">';   
	  }
	  else if($imgsize[0] > $width && $imgsize[1] < $height)
	  {
	     $image =  '<img src="'.$matches[1][$i].'" width="'.$width.'">';
	  } 
	  else if($imgsize[0] < $width && $imgsize[1] > $height)
	  {
	     $image =  '<img src="'.$matches[1][$i].'" height="'.$height.'">';
	  } 
      else if($imgsize[0] > $width && $imgsize[1] > $height)
	  {
	     $image =  '<img src="'.$matches[1][$i].'" height="'.$height.'" width="'.$width.'">';
	  }
	  $return .= preg_replace('#\[ img\](.+)\[ /img\]#U', $image, $var);
	   
	}
	return $return;

	
}
 
Sven hat dir doch schon einen Wink mit dem Zaunpfahl gegeben:
PHP:
<?php

	function foo($string, $width, $height)
	{
		return preg_replace('#\[ img\](.+?)\[ /img\]#s', "bar('\1', '$width', '$height')", $string);
	}

	function bar($src, $width, $height)
	{
		if( ! $imgsize = getimagesize($src) ) {
			return '[ img]'.$src.'[ /img]';
		}
		if( $imgsize[0] < $width && $imgsize[1] < $height ) {
			$image = '<img src="'.$src.'" width="'.$imgsize[0].'">';
		} else if( $imgsize[0] > $width && $imgsize[1] < $height ) {
			$image = '<img src="'.$src.'" width="'.$width.'">';
		} else if( $imgsize[0] < $width && $imgsize[1] > $height ) {
			$image = '<img src="'.$src.'" height="'.$height.'">';
		} else if( $imgsize[0] > $width && $imgsize[1] > $height ) {
			$image = '<img src="'.$src.'" height="'.$height.'" width="'.$width.'">';
		}
		return $image;

	}

?>
Ich hoffe, es funktioniert.
 
Danke, aber irgendwie funktioniert dieser Teil nicht:

PHP:
"bar('\1', '$width', '$height')"
Es wird einfach

bar('r','800',900')

ausgegeben.
 
lautet es doch auch :confused:

Hier nochmals der Code:

PHP:
    function foo($string, $width, $height) 
    { 
        return preg_replace('#\[ img\](.+?)\[ /img\]#s',bar('\1', $width, $height) , $string); 
    } 

    function bar($src, $width, $height) 
    { 
        if( ! $imgsize = getimagesize($src)  ) { 
            return '[ img]'.$src.'[ /img]'; 
        } 
        if( $imgsize[0] < $width && $imgsize[1] < $height ) { 
            $image = '<img src="'.$src.'" width="'.$imgsize[0].'">'; 
        } else if( $imgsize[0] > $width && $imgsize[1] < $height ) { 
            $image = '<img src="'.$src.'" width="'.$width.'">'; 
        } else if( $imgsize[0] < $width && $imgsize[1] > $height ) { 
            $image = '<img src="'.$src.'" height="'.$height.'">'; 
        } else if( $imgsize[0] > $width && $imgsize[1] > $height ) { 
            $image = '<img src="'.$src.'" height="'.$height.'" width="'.$width.'">'; 
        } 
        return $image; 

    }
 
Ja....jetzt seh ich es auch..sehr merkwürdig :confused:

Dann eben so :mad:
PHP:
preg_replace('#\[img\](.+?)\[/img\]#se', "bar('\\1', $width, $height)", $string);
 
Hi Danke Juhu Funktioniert Super.

Echt gutes Forum. :) :)

Aber noch eine frage wiso funkioniert es jetzt :eek:

Fürwas steht dass

#se und dass (.+?) da nimmt mich vorallem das fragezeichen wunder.
 

Neue Beiträge

Zurück