Sie sind hier : sebastian1012.bplaced.net/ homepage-neu / Kurze-Scripte-und-Codeschnipsel / index.php

Zurück


Der Quellcode dazu


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
if(isset($_POST['bild'])){
session_start(); 
$datei $_FILES['datei']['name']; // Dies hab ich noch nicht getestet, da ich den Namen immer nach datum und user id abgespeichert hab. 
$datei str_replace(" ""_""$datei"); 
$datei htmlentities($datei); // Mit leerzeichen -> _ hab ich auch noch nicht getestet, sollte aba klappen 
$dateityp GetImageSize($_FILES['datei']['tmp_name']); 
if(
$dateityp[2] == 2
   { 

   if(
$_FILES['datei']['size'] <  2048000//max. Größe in bytes 
      

      
move_uploaded_file($_FILES['datei']['tmp_name'], "upload/temp-$datei"); 
                  
$file        "upload/temp-$datei"
                  
$target    "upload/$datei"
                  
$max_width   "500"//Breite ändern 
                  
$max_height   "500"//Höhe ändern 
                  
$quality     "90"//Qualität ändern (max. 100) 
                  
$src_img     imagecreatefromjpeg($file); 
                  
$picsize     getimagesize($file); 
                  
$src_width   $picsize[0]; 
                  
$src_height  $picsize[1]; 
                   
                  if(
$src_width $src_height
                  { 
                  if(
$src_width $max_width
                  { 
                    
$convert $max_width/$src_width
                    
$dest_width $max_width
                    
$dest_height ceil($src_height*$convert); 
                  } 
                  else 
                  { 
                    
$dest_width $src_width
                    
$dest_height $src_height
                  } 
                  } 
                  else 
                  { 
                  if(
$src_height $max_height
                  { 
                    
$convert $max_height/$src_height
                    
$dest_height $max_height
                    
$dest_width ceil($src_width*$convert); 
                  } 
                  else 
                  { 
                    
$dest_height $src_height
                    
$dest_width $src_width
                  } 
                  } 
                  
$dst_img imagecreatetruecolor($dest_width,$dest_height); 
                  
imagecopyresampled($dst_img$src_img0000$dest_width$dest_height$src_width$src_height);
                  
imagejpeg($dst_img"$target"$quality); 






// Ab hier wird noch eine Thumbnail erstellt.  
                  
$file2       "upload/$datei"
                  
$target2    "upload/thumbnail-$datei"
                  
$max_width   "150"//Thumbnailbreite 
                  
$max_height   "150"//Thumbnailhöhe 
                  
$quality     "90"//Thumbnailqualität 
                  
$src_img     imagecreatefromjpeg($file2); 
                  
$picsize     getimagesize($file2); 
                  
$src_width   $picsize[0]; 
                  
$src_height  $picsize[1]; 
                   
                  if(
$src_width $src_height
                  { 
                  if(
$src_width $max_width
                  { 
                    
$convert $max_width/$src_width
                    
$dest_width $max_width
                    
$dest_height ceil($src_height*$convert); 
                  } 
                  else 
                  { 
                    
$dest_width $src_width
                    
$dest_height $src_height
                  } 
                  } 
                  else 
                  { 
                  if(
$src_height $max_height
                  { 
                    
$convert $max_height/$src_height
                    
$dest_height $max_height
                    
$dest_width ceil($src_width*$convert); 
                  } 
                  else 
                  { 
                    
$dest_height $src_height
                    
$dest_width $src_width
                  } 
                  } 
                  
$dst_img imagecreatetruecolor($dest_width,$dest_height); 
                  
imagecopyresampled($dst_img$src_img0000$dest_width$dest_height$src_width$src_height);
                  
imagejpeg($dst_img"$target2"$quality); 

                  
unlink($file); 
                  echo 
"<img src=\"upload/$datum-$userid.jpg\">"
                  } 

   else 
      { 
         echo 
"<center><b>Das Bild darf nicht größer als 2MB sein</b></center>"
      } 

    } 

else 
    { 
    echo 
"<center><b>Bitte nur Bilder im JPG Format hochladen</b></center>"
    } 

}





















?>
<form action="bild-hochladen-und-qualitat-andern.php" methode="POST">
<input name="bild" type="file">
<input type="submit">
</form>