PSD-Tutorials.de
Forum für Design, Fotografie & Bildbearbeitung
Tutkit
Agentur
Hilfe
Kontakt
Start
Forum
Aktuelles
Besonderer Inhalt
Foren durchsuchen
Tutorials
News
Anmelden
Kostenlos registrieren
Aktuelles
Suche
Suche
Nur Titel durchsuchen
Von:
Menü
Anmelden
Kostenlos registrieren
App installieren
Installieren
JavaScript ist deaktiviert. Für eine bessere Darstellung aktiviere bitte JavaScript in deinem Browser, bevor du fortfährst.
Du verwendest einen veralteten Browser. Es ist möglich, dass diese oder andere Websites nicht korrekt angezeigt werden.
Du solltest ein Upgrade durchführen oder einen
alternativen Browser
verwenden.
Antworten auf deine Fragen:
Neues Thema erstellen
Start
Forum
Sonstiges
Webdesign, Webentwicklung & Programmierung
PHP, Javascript, jQuery, Ajax, nodeJS, MySQL...
Bildgröße mit PHP
Beitrag
<blockquote data-quote="chiryphp" data-source="post: 1684200"><p><strong>AW: Bildgröße mit PHP</strong></p><p></p><p>PHP Code:</p><p> 001<?php</p><p>002//this class is not part of Resize and upload image class.</p><p>003//this class is property of some one else. </p><p>004//I get this from phpclasses.org but forget the name of author.</p><p>005//sorry for that.</p><p>006 </p><p>007class Image {</p><p>008 var $FileName;</p><p>009 var $FileSize;</p><p>010 var $FileType;</p><p>011 var $AllowedExtentions = array ("image/png", "image/gif", "image/jpeg", "image/pjpeg", "image/jpg"); </p><p>012 var $newWidth = 100; // new width </p><p>013 var $newHeight = 100; //new height</p><p>014 var $TmpName;</p><p>015 var $PicDir; //store uploaded images</p><p>016 var $MaxFileSize = 2000000; //kbytes </p><p>017 var $ImageQuality = 100; // image compression (max value 100)</p><p>018 </p><p>019 function Image($FileName) {</p><p>020 $this->FileName=$FileName;</p><p>021 }</p><p>022 </p><p>023 function GetInfo() {</p><p>024 $out=' <br><br>Upload success!<br></p><p>025 Name: '.$this->FileName.'<br></p><p>026 file size: '.$this->FileSize.' byte<br></p><p>027 file type: '.$this->FileType.'<br></p><p>028 <img src=' . dirname($_SERVER['PHP_SELF']) . '/' . $this->PicDir . $this->FileName . '><br><br>';</p><p>029 </p><p>030 return $out; </p><p>031 }</p><p>032 </p><p>033 </p><p>034 function GetFileExtention ($FileName) {</p><p>035 if (in_array ($this->FileType, $this -> AllowedExtentions)) {</p><p>036 return true; </p><p>037 } else {</p><p>038 return false; </p><p>039 } </p><p>040 </p><p>041 } </p><p>042 </p><p>043 function ExistFile () {</p><p>044 $fileexist = $_SERVER['DOCUMENT_ROOT'] . </p><p>045 dirname($_SERVER['PHP_SELF']) . </p><p>046 '/' . $this->PicDir . </p><p>047 $this->FileName;</p><p>048 if (file_exists($fileexist)) { return true; }</p><p>049 }</p><p>050 </p><p>051 function GetError ($error) {</p><p>052 </p><p>053 switch ($error) { </p><p>054 case 0 :</p><p>055 return "Error: Invalid file type <b>$this->FileType</b>! Allow type: .jpg, .jpeg, .gif, .png <b>$this->FileName</b><br>";</p><p>056 break;</p><p>057 </p><p>058 case 1 :</p><p>059 return "Error: File <b>$this->FileSize</b> is too large! You must upload 1000 MB file<br>";</p><p>060 break; </p><p>061 </p><p>062 case 2 :</p><p>063 return "Error: Please, select a file for uploading!<br>";</p><p>064 break;</p><p>065 </p><p>066 case 3 :</p><p>067 return "Error: File <b>$this->FileName</b> already exist!<br>";</p><p>068 break; </p><p>069 }</p><p>070 </p><p>071 }</p><p>072 </p><p>073 </p><p>074 function Resize () {</p><p>075 // header('Content-Type: image/gif');</p><p>076 if (empty ($this->TmpName)) {return $this -> GetError (2);}</p><p>077 else if ($this->FileSize > $this->MaxFileSize) {return $this -> GetError (1);} </p><p>078 else if ($this -> GetFileExtention ($this->FileName) == false) {return $this -> GetError (0);} </p><p>079 else if ($this -> ExistFile()) {return $this -> GetError (3);}</p><p>080 </p><p>081 else {</p><p>082 </p><p>083 $ext = explode(".",$this->FileName);</p><p>084 $ext = end($ext);</p><p>085 $ext = strtolower($ext);</p><p>086 </p><p>087 // Get new sizes</p><p>088 list($width_orig, $height_orig) = getimagesize($this->TmpName);</p><p>089 </p><p>090 $ratio_orig = $width_orig/$height_orig;</p><p>091 </p><p>092 if ($this->newWidth/$this->newHeight > $ratio_orig) {</p><p>093 $this->newWidth = $this->newHeight*$ratio_orig;</p><p>094 } else {</p><p>095 $this->newHeight = $this->newWidth/$ratio_orig;</p><p>096 }</p><p>097 </p><p>098 $normal = imagecreatetruecolor($this->newWidth, $this->newHeight);</p><p>099 </p><p>100 if ($ext == "jpg") { $source = imagecreatefromjpeg($this->TmpName); }</p><p>101 else if ($ext == "gif") { $source = imagecreatefromgif ($this->TmpName); }</p><p>102 else if ($ext == "png") </p><p>103 { </p><p>104 $this->ImageQuality = 9;</p><p>105 $source = imagecreatefrompng ($this->TmpName); </p><p>106 }</p><p>107 </p><p>108 imagecopyresampled($normal, $source, 0, 0, 0, 0, $this->newWidth, $this->newHeight, $width_orig, $height_orig);</p><p>109 </p><p>110 </p><p>111 if ($ext == "jpg") { </p><p>112 //ob_start();</p><p>113 imagejpeg($normal, "$this->PicDir/$this->FileName", "$this->ImageQuality"); </p><p>114 //$binaryThumbnail = ob_get_contents(); </p><p>115 //ob_end_clean(); </p><p>116 }</p><p>117 else if ($ext == "gif") { imagegif ($normal, "$this->PicDir/$this->FileName", "$this->ImageQuality"); }</p><p>118 else if ($ext == "png") { imagepng ($normal, "$this->PicDir/$this->FileName", "$this->ImageQuality"); }</p><p>119 </p><p>120 imagedestroy($source);</p><p>121 </p><p>122 //echo $this -> GetInfo();</p><p>123 </p><p>124 } </p><p>125 </p><p>126 } </p><p>127 </p><p>128 function Save() { </p><p>129 if (empty ($this->TmpName)) {return $this -> GetError (2);}</p><p>130 else if ($this->FileSize > $this->MaxFileSize) {return $this -> GetError (1);} </p><p>131 else if ($this -> GetFileExtention ($this->FileName) == false) {return $this -> GetError (0);} </p><p>132 else if ($this -> ExistFile ()) {return $this -> GetError (3);} </p><p>133 </p><p>134 else {</p><p>135 </p><p>136 copy($this->TmpName,$this->PicDir.$this->FileName);</p><p>137 </p><p>138 //echo $this -> GetInfo();</p><p>139 </p><p>140 }</p><p>141 }</p><p>142 }</p><p>143 </p><p>144?></p><p></p><p></p><p></p><p><a href="http://www.phpkode.com/source/s/easy-upload-resize-thumb-image-6258/resizeupload/imageresizer.class.php#about" target="_blank"></a></p><p><a href="http://www.phpkode.com/source/s/easy-upload-resize-thumb-image-6258/resizeupload/imageresizer.class.php#about" target="_blank"></a></p><p> Einige <a href="http://www.phpkode.com/projects/category/php-pdf/" target="_blank">PHP </a><a href="http://www.phpkode.com/projects/category/php-pdf/" target="_blank">PDF</a> Skripte im auf der Seite aufgelistet</p></blockquote><p></p>
[QUOTE="chiryphp, post: 1684200"] [b]AW: Bildgröße mit PHP[/b] PHP Code: 001<?php 002//this class is not part of Resize and upload image class. 003//this class is property of some one else. 004//I get this from phpclasses.org but forget the name of author. 005//sorry for that. 006 007class Image { 008 var $FileName; 009 var $FileSize; 010 var $FileType; 011 var $AllowedExtentions = array ("image/png", "image/gif", "image/jpeg", "image/pjpeg", "image/jpg"); 012 var $newWidth = 100; // new width 013 var $newHeight = 100; //new height 014 var $TmpName; 015 var $PicDir; //store uploaded images 016 var $MaxFileSize = 2000000; //kbytes 017 var $ImageQuality = 100; // image compression (max value 100) 018 019 function Image($FileName) { 020 $this->FileName=$FileName; 021 } 022 023 function GetInfo() { 024 $out=' <br><br>Upload success!<br> 025 Name: '.$this->FileName.'<br> 026 file size: '.$this->FileSize.' byte<br> 027 file type: '.$this->FileType.'<br> 028 <img src=' . dirname($_SERVER['PHP_SELF']) . '/' . $this->PicDir . $this->FileName . '><br><br>'; 029 030 return $out; 031 } 032 033 034 function GetFileExtention ($FileName) { 035 if (in_array ($this->FileType, $this -> AllowedExtentions)) { 036 return true; 037 } else { 038 return false; 039 } 040 041 } 042 043 function ExistFile () { 044 $fileexist = $_SERVER['DOCUMENT_ROOT'] . 045 dirname($_SERVER['PHP_SELF']) . 046 '/' . $this->PicDir . 047 $this->FileName; 048 if (file_exists($fileexist)) { return true; } 049 } 050 051 function GetError ($error) { 052 053 switch ($error) { 054 case 0 : 055 return "Error: Invalid file type <b>$this->FileType</b>! Allow type: .jpg, .jpeg, .gif, .png <b>$this->FileName</b><br>"; 056 break; 057 058 case 1 : 059 return "Error: File <b>$this->FileSize</b> is too large! You must upload 1000 MB file<br>"; 060 break; 061 062 case 2 : 063 return "Error: Please, select a file for uploading!<br>"; 064 break; 065 066 case 3 : 067 return "Error: File <b>$this->FileName</b> already exist!<br>"; 068 break; 069 } 070 071 } 072 073 074 function Resize () { 075 // header('Content-Type: image/gif'); 076 if (empty ($this->TmpName)) {return $this -> GetError (2);} 077 else if ($this->FileSize > $this->MaxFileSize) {return $this -> GetError (1);} 078 else if ($this -> GetFileExtention ($this->FileName) == false) {return $this -> GetError (0);} 079 else if ($this -> ExistFile()) {return $this -> GetError (3);} 080 081 else { 082 083 $ext = explode(".",$this->FileName); 084 $ext = end($ext); 085 $ext = strtolower($ext); 086 087 // Get new sizes 088 list($width_orig, $height_orig) = getimagesize($this->TmpName); 089 090 $ratio_orig = $width_orig/$height_orig; 091 092 if ($this->newWidth/$this->newHeight > $ratio_orig) { 093 $this->newWidth = $this->newHeight*$ratio_orig; 094 } else { 095 $this->newHeight = $this->newWidth/$ratio_orig; 096 } 097 098 $normal = imagecreatetruecolor($this->newWidth, $this->newHeight); 099 100 if ($ext == "jpg") { $source = imagecreatefromjpeg($this->TmpName); } 101 else if ($ext == "gif") { $source = imagecreatefromgif ($this->TmpName); } 102 else if ($ext == "png") 103 { 104 $this->ImageQuality = 9; 105 $source = imagecreatefrompng ($this->TmpName); 106 } 107 108 imagecopyresampled($normal, $source, 0, 0, 0, 0, $this->newWidth, $this->newHeight, $width_orig, $height_orig); 109 110 111 if ($ext == "jpg") { 112 //ob_start(); 113 imagejpeg($normal, "$this->PicDir/$this->FileName", "$this->ImageQuality"); 114 //$binaryThumbnail = ob_get_contents(); 115 //ob_end_clean(); 116 } 117 else if ($ext == "gif") { imagegif ($normal, "$this->PicDir/$this->FileName", "$this->ImageQuality"); } 118 else if ($ext == "png") { imagepng ($normal, "$this->PicDir/$this->FileName", "$this->ImageQuality"); } 119 120 imagedestroy($source); 121 122 //echo $this -> GetInfo(); 123 124 } 125 126 } 127 128 function Save() { 129 if (empty ($this->TmpName)) {return $this -> GetError (2);} 130 else if ($this->FileSize > $this->MaxFileSize) {return $this -> GetError (1);} 131 else if ($this -> GetFileExtention ($this->FileName) == false) {return $this -> GetError (0);} 132 else if ($this -> ExistFile ()) {return $this -> GetError (3);} 133 134 else { 135 136 copy($this->TmpName,$this->PicDir.$this->FileName); 137 138 //echo $this -> GetInfo(); 139 140 } 141 } 142 } 143 144?> [URL="http://www.phpkode.com/source/s/easy-upload-resize-thumb-image-6258/resizeupload/imageresizer.class.php#about"] [/URL] Einige [URL="http://www.phpkode.com/projects/category/php-pdf/"]PHP [/URL][URL="http://www.phpkode.com/projects/category/php-pdf/"]PDF[/URL] Skripte im auf der Seite aufgelistet [/QUOTE]
Bilder bitte
hier hochladen
und danach über das Bild-Icon (Direktlink vorher kopieren) platzieren.
Zitate einfügen…
Authentifizierung
Wenn ★ = 12, ◇ = 4 und die Hälfte von ★ zu ◇ addiert wird, was ist das Ergebnis?
Antworten
Start
Forum
Sonstiges
Webdesign, Webentwicklung & Programmierung
PHP, Javascript, jQuery, Ajax, nodeJS, MySQL...
Bildgröße mit PHP
Oben