Autor | Zpráva | ||
---|---|---|---|
195filip Profil * |
#1 · Zasláno: 23. 2. 2011, 17:45:58
Ahoj...
mám takýto kód: <?php if ($ok){ $subor = "fotogaleria.php"; $fp = fopen($subor, "r+") or die ("Nieje možné vytvoriť zadaný súbor!"); for ($i = 1; $i <= 5; $i++) { $fotka = "fotka" . $i; $fotka_name = $fotka . "_name"; $fotka_type = $fotka . "_type"; $fotka_size = $fotka . "_size"; if ($$fotka_type=="image/jpeg" || $$fotka_type=="image/pjpeg" || $$fotka_type=="image/gif" || $$fotka_type=="image/png") { copy($$fotka, "./fotogaleria/{$$fotka_name}"); fwrite($fp, "<a href=\"./fotogaleria/{$$fotka_name}\" rel=\"lightbox[1]\">"); fwrite($fp, "<img src=\"./fotogaleria/{$$fotka_name}\" class=\"foto\"></a>\n"); } } fclose($fp); } ?> <form action="<?php echo $PHP_SELF ?>" method="post" enctype="multipart/form-data"> <table border="1"> <tr><th>Fotky</th><th>Súbor</th></tr> <tr><td>1</td><td><input type="file" name="fotka1"></td></tr> <tr><td>2</td><td><input type="file" name="fotka2"></td></tr> <tr><td>3</td><td><input type="file" name="fotka3"></td></tr> <tr><td>4</td><td><input type="file" name="fotka4"></td></tr> <tr><td>5</td><td><input type="file" name="fotka5"></td></tr> </table> <input type="submit" name="ok" value="Vložiť"> </form> a potreboval by som tam dorobiť aby sa fotka zmenšila na 150x106px čo by sa uložilo do priečinku small a normálna pridaná by sa uložila do priečinku full. No a výsledný súbor by sa zapisoval takto: <h2>Fotogaléria</h2> <div class="fotogaleria"> <!-- VLOŽENÉ FOTKY --> </div> <div style="display: none;"> Viete mi s tým nejako pomôcť ? alebo je celý kód zle ? Ďakujem |
||
Matthew113 Profil |
#2 · Zasláno: 23. 2. 2011, 17:50:11
Na tvůj název tématu (resize image php) mi google poradil pár zajímavých scriptů... Zkusil jsi ho?
http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php |
||
195filip Profil * |
#3 · Zasláno: 23. 2. 2011, 17:55:09
no ja som tiež takto hľadal ale akosi to neviem do toho kódu zaimplementovať. Ja sa do PHP dáko nevyznám :(
|
||
Matthew113 Profil |
#4 · Zasláno: 23. 2. 2011, 19:03:53 · Upravil/a: Matthew113
195filip:
V jednom souboru si definuješ funkce a třídy (což je první část kódu na stránkách), tedy: funkce.php: <?php /* * * File: SimpleImage.php * Author: Simon Jarvis * Copyright: 2006 Simon Jarvis * Date: 08/11/06 * Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * http://www.gnu.org/licenses/gpl.html * */ class SimpleImage { var $image; var $image_type; function load($filename) { $image_info = getimagesize($filename); $this->image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg($filename); } elseif( $this->image_type == IMAGETYPE_GIF ) { $this->image = imagecreatefromgif($filename); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image,$filename); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image,$filename); } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image); } } function getWidth() { return imagesx($this->image); } function getHeight() { return imagesy($this->image); } function resizeToHeight($height) { $ratio = $height / $this->getHeight(); $width = $this->getWidth() * $ratio; $this->resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this->getWidth(); $height = $this->getheight() * $ratio; $this->resize($width,$height); } function scale($scale) { $width = $this->getWidth() * $scale/100; $height = $this->getheight() * $scale/100; $this->resize($width,$height); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } } ?> Po nahrání souboru na web zadáš jeho umístění a potřebné informace k vytvoření nového obrázku <?php include('funkce.php'); $image = new SimpleImage(); $image->load('UMISTENI_STAREHO_OBRAZKU'); // kde je obrázek, který chceš zmenšit, tedy například '../images/test.png' $image->resize(150,106); // šířka, výška $image->save('UMISTENI_NOVEHO_OBRAZKU_'); // kam chceš nový obrázek (zmenšený) nahrát, například '../images/male/test.png' ?> Mimochodem, zpátky k tvému scriptu. Odkdy se používají dva dolary? ($$) if ($$fotka_type=="image/jpeg" || $$fotka_type=="image/pjpeg" || $$fotka_type=="image/gif" || $$fotka_type=="image/png") By šlo přepsat na if(in_array($fotka_type,array('image/jpeg','image/pjpeg','image/gif','image/png'))) |
||
Darker Profil |
#5 · Zasláno: 23. 2. 2011, 19:39:41
Matthew113:
„Odkdy se používají dva dolary? ($$)“ Nevím jestli to tam měl naschvál, ale funkce toho zápisu je následující: $pepa=3; $neco="pepa"; echo $$neco; //Melo by vypsat 3 |
||
Časová prodleva: 13 let
|
0