mtk-flo
Erfahrenes Mitglied
Also ich lad ein Bild hoch.
Es wird auf dem Server gespeichert. Anschließend hol ich mir von dem Bild die Größe ( Breite und Höhe ) und wenn die Breite größer ist als 1024, dann nehm ich mir das Bild noch mal und verkleiner es auf eine Breite von 1024 pixel.
Jedoch geht das Script nicht so ganz...
WARUM ?
Hier mein Verkleiner Script:
hier kommt nochmal mein ganzes Script
Es wird auf dem Server gespeichert. Anschließend hol ich mir von dem Bild die Größe ( Breite und Höhe ) und wenn die Breite größer ist als 1024, dann nehm ich mir das Bild noch mal und verkleiner es auf eine Breite von 1024 pixel.
Jedoch geht das Script nicht so ganz...
WARUM ?
Hier mein Verkleiner Script:
PHP:
list($width,$height)=getimagesize("gallery/".$ordner."/".$bilddatei_name);
$sourceimage=imagecreatefromjpeg("gallery/".$ordner."/".$bilddatei_name);
if($width > 1024)
{
$thumbwidth=1024;
$thumbheight=round($thumbwidth*($height/$width));
}
else
{
$thumbwidth=$width;
$thumbheight=$height;
}
//$thumbheight = 200;
//$thumbwidth = round($thumbheight*($width/$height));
$thumbimage=imagecreatetruecolor($thumbwidth,$thumbheight);
imagecopyresampled($thumbimage,$sourceimage,0,0,0,0,$thumbwidth,$thumbheight,$width,$height);
imagejpeg($thumbimage,"gallery/".$ordner."/".$bilddatei_name);
hier kommt nochmal mein ganzes Script
PHP:
$section_id = $_POST['section_id'];
$beschreibung = $_POST['beschreibung'];
$res = mysql_query("SELECT * FROM mtk_gallery_section WHERE id = '".$section_id."';");
$array = mysql_fetch_array($res);
$ordner = $array['ordner'];
if($bilddatei == "")
{
echo "<table WIDTH='475' align='center' style=\"border-collapse:collapse;\">
<tr>
<td style='border: solid 1px #000000;'>
<TABLE ALIGN='CENTER' WIDTH='470' BORDER='0' cellpadding='2' CELLSPACING=0 class='menu'>
<TR>
<TD valign='top' BGCOLOR='345464' align='center'><b><font color='FFFFFF'>Bild hinzufügen</font></b></TD>
</TR>
<TR>
<TD valign='top' align='center'>Es wurde kein Bild ausgewählt !<br><br>
<a href='admin_gallery?do=new_bild§ion_id=".$section_id."'>Zurück zum Upload</a></TD>
</TR>
</TABLE>
</td>
</tr>
</table>";
}
else
{
$error1 = 0;
$error2 = 0;
$error3 = 0;
$extlimit = "yes"; //Do you want to limit the extensions of files uploaded
$limitedext = array(".gif",".jpg",".png",".jpeg",".GIF",".JPG",".PNG",".JPEG"); //Extensions you want files uploaded limited to.
$sizelimit = "no"; //Do you want a size limit, yes or no?
$sizebytes = "1024000"; //size limit in bytes ( 1 MB )
if($senden){
if (($sizelimit == "yes") && ($bilddatei_size > $sizebytes)) {
$error3 = 1;
}
$ext = strrchr($bilddatei_name,'.');
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
$error1 = 1;
}
//Der Ordner images liegt auf dem Server, dort werde die Bilder kopiert.
//falls im images Ordner der Name der Bilddatei schon existiert, dann soll eine Fehlermeldung kommen.
elseif (file_exists("gallery/".$ordner."/".$bilddatei_name)) {
$error2 = 1;
}
//ansonsten wird die Datei im Ordner images kopiert
else{
$bilddatei_name = str_replace("ö","oe",$bilddatei_name);
$bilddatei_name = str_replace("ä","ae",$bilddatei_name);
$bilddatei_name = str_replace("ü","ue",$bilddatei_name);
$bilddatei_name = str_replace("ß","ss",$bilddatei_name);
$bilddatei_name = str_replace(" ","_",$bilddatei_name);
copy($bilddatei,"gallery/".$ordner."/".$bilddatei_name);
/** BILD BEGRENZUNG ******************/
list($width,$height)=getimagesize("gallery/".$ordner."/".$bilddatei_name);
$sourceimage=imagecreatefromjpeg("gallery/".$ordner."/".$bilddatei_name);
if($width > 1024)
{
$thumbwidth=1024;
$thumbheight=round($thumbwidth*($height/$width));
}
else
{
$thumbwidth=$width;
$thumbheight=$height;
}
//$thumbheight = 200;
//$thumbwidth = round($thumbheight*($width/$height));
$thumbimage=imagecreatetruecolor($thumbwidth,$thumbheight);
imagecopyresampled($thumbimage,$sourceimage,0,0,0,0,$thumbwidth,$thumbheight,$width,$height);
imagejpeg($thumbimage,"gallery/".$ordner."/".$bilddatei_name);
/** BILD BEGRENZUNG ******************/
mysql_query("INSERT INTO mtk_gallery VALUES('','".$beschreibung."','".$bilddatei_name."','".$section_id."','0','0','0','0','0','0','0','0')");
}
}//if($senden)
echo "<table WIDTH='475' align='center' style=\"border-collapse:collapse;\">
<tr>
<td style='border: solid 1px #000000;'>
<TABLE ALIGN='CENTER' WIDTH='470' BORDER='0' cellpadding='2' CELLSPACING=0 class='menu'>
<TR>
<TD valign='top' BGCOLOR='345464' align='center'><b><font color='FFFFFF'>Bild hinzufügen</font></b></TD>
</TR>";
if($error1 == 1)
{
echo "<TR>
<TD valign='top' align='center' BGCOLOR='EAECED'><font color='#CC0000'>Die Bilddatei \"".$bilddatei_name."\" hat nicht die richtige Endung</font></TD>
</TR>";
}
if($error2 == 1)
{
echo "<TR>
<TD valign='top' align='center' BGCOLOR='EAECED'><font color='#CC0000'>Die Bilddateiname \"".$bilddatei_name."\" existiert bereit. Bitte ändere deine Bilddateiname und versuche es nochmal.</font></TD>
</TR>";
}
if($error3 == 1)
{
{
echo "<TR>
<TD valign='top' align='center' BGCOLOR='EAECED'>Die Bilddatei \"".$bilddatei_name."\" ist zu gross, sie darf mamimal $sizebytes bytes sein.</TD>
</TR>";
}
}
if(($error1 == 0) && ($error2 == 0) && ($error3 == 0))
{
echo "<TR>
<TD valign='top' align='center' BGCOLOR='EAECED'>Bildupload \"".$bilddatei_name."\" war erfolgreich</TD>
</TR>";
}
echo "<TR>
<TD valign='top' align='center'><a href='admin_gallery?do=new_bild§ion_id=".$section_id."'>Zurück zum Upload</a></TD>
</TR>
<TR>
<TD valign='top' align='center' BGCOLOR='EAECED'><a href='admin_gallery?do=add_pic&id=".$section_id."'>Zurück zur Übersicht</a></TD>
</TR>
</TABLE>
</td>
</tr>
</table>";
}