knack: Bild verkleinern

Beitrag lesen

Hallo,

<?php
$Pfad = '../uploads/temp/'.$_SESSION['MM_CO'].'.jpg';
$ok = 'nein'; $falsch = 'ja'; $nurJPG = 'ja';

$Speicher = memory_get_usage() . "\n";  # freier RAM Speicher
$Speicher = '3096000';

$dateityp = getimagesize($_FILES['datei']['tmp_name']);
if($dateityp[2] != 0 and $dateityp[2] == 2)
   {

if($_FILES['datei']['size'] <  $Speicher)
     {
     move_uploaded_file($_FILES['datei']['tmp_name'], $Pfad);
     $ok = 'ja';
     }
    else
     {
      $falsch = 'nein';
     }
    }

else
    {
 $nurJPG = 'nein';
    }
?>

<?php
 if( $ok == 'ja' ) #  ANFANG if( $ok == 'ja' )
{
 $bild_ok = 'nein';

$Bild = $_SESSION['MM_CO'].'.jpg'; # bildname
 $Pfad1 = '../uploads/temp'; # von wo?
 $Pfad2 = '../uploads'; # nach wo
 $max_b = 158;     # maximale Breite des Bildes
 $max_h = 200;  # maximale Höhe des Bildes

#  $src_img = LoadJpeg($Pfad1.'/'.$Bild);
 $src_img = imagecreatefromjpeg($Pfad1.'/'.$Bild);

$oh = imagesy($src_img);  # original Höhe
 $ob = imagesx($src_img);  # original Breite

if ( $oh > $max_h and $ob > $max_b ) # ANFANG   if   Bilder, größer als $max
 {

# Breite > Höhe
  if( $ob > $oh ) #  ANFANG if( $ob > $oh )
  {
   $neu_b = $max_b;
   $neu_h =  $oh / ($ob / $max_b);
   if ( $neu_h > $max_b ){$neu_h = $max_h; $neu_b =  $ob / ($oh / $max_h);}
  }#  ENDE if( $ob > $oh )

# Höhe > Breite
  if( $oh > $ob ) #  ANFANG if( $oh > $ob )
  {
   $neu_h = $max_h;
   $neu_b =  $ob / ($oh / $max_h);
   if ( $neu_b > $max_b ) {$neu_b = $max_b; $neu_h =  $oh / ($ob / $max_b);}
  }#  ENDE ANFANG if( $oh > $ob )

# QUADRAT
  if( $oh == $ob and $ob > $max_b) #  ANFANG if( $oh == $ob )
  {
   $neu_b = $max_b;
   $neu_h = $max_b;
  }#  ENDE ANFANG if( $oh == $ob )

}  # ENDE  if   Bilder, größer als $max
 else
 { # ANFANG  else    Bilder, größer als $max ( Bild ist kleiner als max )
  $neu_b = $ob;
  $neu_h = $oh;
 }# ENDE  else    Bilder, größer als $max  ( Bild ist kleiner als max )

$dst_img = imagecreatetruecolor($neu_b,$neu_h);
 // imagecopyresized erzeugt schlechteres Bild als imagecopyresampled
 imagecopyresampled($dst_img, $src_img, 0,0,0,0, $neu_b, $neu_h, imagesx($src_img), imagesy($src_img));

imagejpeg($dst_img, $Pfad2.'/'.$Bild);

# Datei in temp löschen
 unlink ($Pfad1.'/'.$Bild);

$bild_ok = 'ja';
}  #  ENDE if( $ok == 'ja' )
?>

imagecreatefromjpeg sammelt doch nur Informationen von der Datei!?

knack