Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Kompresja obrazka przed wyswietleniem na stronie
Forum PHP.pl > Forum > PHP
bobens_83
Witam. Mam pytanko, czy mozliwe jest aby przechowywac obrazki w katalogu na serwerze a w bazie jedynie ich ID. Nastepnie na stronie glownej (cos jak system news) wyswietlaja sie w petli obrazki, np 10 sztuk (skompresowane miniaturki obrazkow z katalogu). po kliknieciu na obrazek ten sie powieksza i pokazuje w oryginalnej rozdzielczosci. Jestli ma to sens to jakie funkcje PHP moga byc pomocne ? Pozdrawiam.
beton
Hm, przechowywanie jedynie ID obrazków ... najlepiej odrazu człon nazwowy do tego rozszerzenie oraz numer id dla identyfikacji ktory to numer obrazka

funkcje pomocne: wszystkie z zakresu image* , jezeli chcesz tworzyc miniaturki lepiej poszukac gotowej biblioteki (jest chyba php thumbnailer), wiadomo zbieranie wyników z bazy danych przez mysql_query i mysql_fetch (aczkolwiek wole biblioteke ADODB) itd.
bobens_83
  1. <?php
  2. resizeToFile("graphics/test01.jpg", 100, 70, "graphics/test02.jpg", 75);
  3.  
  4. /* resizeToFile resizes a picture and writes it to the harddisk
  5.  * 
  6.  * $sourcefile = the filename of the picture that is going to be resized
  7.  * $dest_x  = X-Size of the target picture in pixels
  8.  * $dest_y  = Y-Size of the target picture in pixels
  9.  * $targetfile = The name under which the resized picture will be stored
  10.  * $jpegqual  = The Compression-Rate that is to be used
  11.  */
  12. function resizeToFile ($sourcefile, $dest_x, $dest_y, $targetfile, $jpegqual) {
  13. /* Get the dimensions of the source picture */
  14. $picsize=getimagesize("$sourcefile");
  15.  
  16. $source_x = $picsize[0];
  17. $source_y = $picsize[1];
  18. $source_id = imagecreatefromjpeg("$sourcefile");
  19.  
  20. /* Create a new image object (not neccessarily true colour) */
  21. $target_id=imagecreatetruecolor($dest_x, $dest_y);
  22.  
  23. /* Resize the original picture and copy it into the just created image
  24.    object. Because of the lack of space I had to wrap the parameters to
  25.    several lines. I recommend putting them in one line in order keep your
  26.    code clean and readable */
  27. $target_pic=imagecopyresampled($target_id,$source_id,
  28.  0,0,0,0,
  29.  $dest_x,$dest_y,
  30.  $source_x,$source_y);
  31.  
  32. /* Create a jpeg with the quality of "$jpegqual" out of the
  33.    image object "$target_pic".
  34.    This will be saved as $targetfile */
  35. imagejpeg ($target_id,"$targetfile",$jpegqual);
  36. return true;
  37. }
  38. ?>



zwraca:

Fatal error: Call to undefined function imagecreatefromjpeg()

Po wykomentowaniu tej linii wywala sie na kolejnej funkcji image*. Co moze byc przyczyna? Czy musze jeszcze cos zainkludowac?
hondek
Nie masz chyba biblioteki GD w PHP poprostu winksmiley.jpg
bobens_83
Tutaj czytam ze

Windows

The php_gd2.dll is included in a standard PHP installation for Windows, it's not enabled by default. You have to turn it on, the user may simply uncomment the line "extension=php_gd2.dll" in php.ini and restart the PHP extension.

Change:

#extension=php_gd2.dll

To:

extension=php_gd2.dll

You may also have to correct the extension directory setting from:

extension_dir = "./"

Or:

extension_dir = "./extensions"





w pliku php.ini odkomentowalem wiec ';extension=php_gd2.dll' -> 'extension=php_gd2.dll' . Poniewaz w pliku php.ini nie znalazlem slowa 'extension_dir' nie zrobilem z tym nic. zrestartowalem wszystkie uslugi i ciagle lipa sad.gif





phpinfo pokazuje ze wszystko jest ok:
gd
GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.1.9
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.