• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

PHP Bildbearbeitung

Status
Für weitere Antworten geschlossen.

dreamweaver_8

Neues Mitglied
Hallo,

ich habe eine Frage: Wie kann ich mit PHP die bildgrösse verändern, das ich sagen kann das bild darf nicht grösser als z.B. 200 x 150 px sein, aber kleiner, Ohne das das bild verzerrt wird.
 
Werbung:
PHP:
$imgx = imagesx(src);
$imgy = imagesy(src);
$maxw = 200;
$maxh = 150;
$ratio = $imgx/$imgy;

if ( $imgx > $maxw ) {
 if ( $imgy > $maxy ) {
  $diffx = $imgx - $maxw;
  $diffy = $imgy - $maxy;
  if ( $diffx > $diffy ) {
   $do = 1;
  } else {
   $do = 2;
  }
 } else {
  $do = '1';
 }
} elseif ( $imgy > $maxy ) {
 $do = '2';
}

switch($do) {
 case "1": 
  if ( $ratio > 1 ) {
   $newwidth = $maxw;
   $newheight = $maxw/$ratio;
  } else {
   $newwidth = $maxw;
   $newheight = $maxw*$ratio;
  }
 break;
 case "2": 
  if ( $ratio > 1 ) {
   $newheight = $maxh;
   $newwidth = $maxh/$ratio;
  } else {
   $newheight = $maxh;
   $newwidth = $maxh*$ratio;
  }
 break;
 default: break; }

probier mal, konnts aber ned testen
 
Zuletzt bearbeitet:
Parse error: parse error, unexpected T_ELSE in /home/manuelg/public_html/mybild/test.php on line 46
Und wo kommt überhaupt das bild rein das verändert werden soll?
43 $newheight = $maxh;
44 $newwidth = $maxh/$ratio;
45 }
46 else
47 {
48 $newheight = $maxh;
49 $newwidth = $maxh*$ratio;
50 }
 
Werbung:
Status
Für weitere Antworten geschlossen.
Zurück
Oben