Problem mit Bilder einfügen Script

newwarrior

Erfahrenes Mitglied
mit diesem script können bei mir diekret bilder im Beitrag eingefügt werden. Das läuft auch. Jetzt wollte ich aber es so machen, das die bilder auf ein bestimme größer verkleinert werden, und wenn man auf sie klick zum orgnial kommt. aber ich schaffe es nicht mit der verkleinerung. k�nntet ihr mir helfen:


PHP:
<?php

$text = preg_replace("/\[img\](.*)\[\/img\]/isUe", "imagelink('\\1')", $text);

function imagelink($url) {
$maxwidth = 400;
$maxheight = 300;
$imgsize = getimagesize($url);
$imgsize = explode("\"", $imgsize[3]);
$imgwidth = $imgsize[1];
$imgheight = $imgsize[3];

if ( ($imgwidth > $maxwidth) OR ($imgheight > $maxheight) ) {

$t = true;
$width = $maxwidth;
$height = $maxheight;

//hier soll es weiter gehen

}
if ($t == true) {
$img_link = "<a href=\"".$url."\"><img src=\"" .$url ."\" style=\"width: ".$width."px; height: ".$height."px; \" /></a>";

} else {

$img_link = "<img src=\"" .$url ."\" />";  

}
return $img_link;
}

?>
?>
 
Willst Du ein Thumbnail erstellen oder einfach nur mittels $width und $height das Bild kleiner ausgeben lassen?
Anhand Deines Codes wuerde ich auf das 2. tippen.

Also:
PHP:
if ( ($imgwidth > $maxwidth) OR ($imgheight > $maxheight) ) { 

$t = true; 
$width=$imgwidth;
$height=$imgheight;
if ($width>$maxwidth)
 {
  $height=($maxwidth/$width)*$height;
  $width=$maxwidth;
 }
if ($height>$maxheight)
 {
  $width=($maxheight/$height)*$width;
  $height=$maxheight;
 }  
 }
//hier soll es weiter gehen 

}
So sollte es eigentlich gehen.
Ich geb aber keine Garantie, ist spontan getippt.
 
Zurück