giraffe35
Threadersteller
Dabei seit: 29.08.2010
Ort: -
Alter: -
Geschlecht: -
|
Verfasst So 29.08.2010 21:01
Titel bilder proportional verkleinern |
|
|
hi
Ich kann die Bilder in der Breite verkleinern, doch wenn die Bilder hochformatig sind sollte ich sie in der Höhe verkleinern,
Code: | $sizes = array(
array('prepend' => '', 'maxw' => 664), // grosses bild max 400 pixel breit
array('prepend' => 'k_', 'maxw' => 216), // mittleres bild max 150 pixel breit
);
foreach ($sizes as $size) {
// neue dimensionen berechnen
if ($size['maxw'] > 0 && $sx > $size['maxw']) {
$neww = $size['maxw'];
$newh = $sy * ($neww / $sx);
$dest_img = imagecreatetruecolor($neww, $newh);
imagecopyresampled($dest_img, $img, 0, 0, 0, 0, $neww, $newh, $sx, $sy);
}
// bild unverändert lassen
else
$dest_img = $img;
// bild abspeichern
switch ($type) {
case 'gif':
if (!imagegif($dest_img, $dest_path . $size['prepend'] . $dest_file . ".$type"))
return false;
break;
case 'jpg':
if (!imagejpeg($dest_img, $dest_path . $size['prepend'] . $dest_file . ".$type", 90))
return false;
break;
case 'png':
if (!imagegif($dest_img, $dest_path . $size['prepend'] . $dest_file . ".$type", 9))
return false;
break;
}
}
|
Anbei mein Versuch. Aber schon das foreach geht nicht, keine Ahnung wieso.
Code: | $hoehen = array(
array('prepend' => '', 'maxh' => 493), // grosses bild max 400 pixel breit
array('prepend' => 'k_', 'maxh' => 162), // mittleres bild max 150 pixel breit
);
foreach ($hoehen as $hoehe) {
// neue dimensionen berechnen
if ($hoehe['maxh'] > 0 && $sy > $hoehe['maxh']) {
$newh = $size['maxh'];
$neww = $sx * ($newh / $sy);
$dest_img = imagecreatetruecolor($neww, $newh);
imagecopyresampled($dest_img, $img, 0, 0, 0, 0, $neww, $newh, $sx, $sy);
}
// bild unverändert lassen
else
$dest_img = $img;
// bild abspeichern
switch ($type) {
case 'gif':
if (!imagegif($dest_img, $dest_path . $size['prepend'] . $dest_file . ".$type"))
return false;
break;
case 'jpg':
if (!imagejpeg($dest_img, $dest_path . $size['prepend'] . $dest_file . ".$type", 90))
return false;
break;
case 'png':
if (!imagegif($dest_img, $dest_path . $size['prepend'] . $dest_file . ".$type", 9))
return false;
break;
}
} |
wie kann ich hochformatige Bilder der höhe anpassen udn quere in der Breite?
|
|