Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> longblob wyciąganie obrazka i resize, PHP +mySQL
vahooz
post 8.03.2007, 02:40:32
Post #1





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 28.05.2006

Ostrzeżenie: (0%)
-----


Witam.

Posiadam bazę z obrazkami (wszystkie o rozdzielczości 800x600), teraz chciałbym je wyświetlić jako miniaturki. Jak dokonać takiej konwersji? Plik wyświetlający obrazek:
  1. <?php
  2. if(!isset($Id)) die("Need 'Id' parameter");
  3. else $Id=addslashes($Id);
  4. include("common.php");
  5. //set up SQL connection
  6. $link = mysql_connect ($server, $user, $password);
  7. if (! $link) die ("Couldn't connect to mySQL server");
  8. if (!mysql_select_db ($db, $link) ) die ("Coldn't open $db: ".mysql_error() );
  9. $query = "SELECT filetype, bin_data FROM tbl_Files WHERE id_files='$Id';";
  10. $result = mysql_query($query);
  11. $query_data = mysql_fetch_array($result);
  12. $bin_data = $query_data[bin_data];
  13. $filetype = $query_data[filetype];
  14. Header("Content-type: $filetype");
  15. echo $bin_data;
  16. ?>


Pozdrawiam.


--------------------
shit, fuck and microsoft
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 7)
SongoQ
post 8.03.2007, 06:51:08
Post #2





Grupa: Przyjaciele php.pl
Postów: 2 923
Pomógł: 9
Dołączył: 25.10.2004
Skąd: Rzeszów - studia / Warszawa - praca

Ostrzeżenie: (0%)
-----


http://pl.php.net/manual/pl/function.imagecopyresampled.php


--------------------
Go to the top of the page
+Quote Post
vahooz
post 8.03.2007, 12:46:55
Post #3





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 28.05.2006

Ostrzeżenie: (0%)
-----


Tej funkcji nie mogę zastosować do obrazka władowanego do bazy, przecież nie mam uchwytu do obrazka, tylko jego binarną zawartość. Proszę poprawcie mnie jak jestem w błędzie.

Pozdrawiam.


--------------------
shit, fuck and microsoft
Go to the top of the page
+Quote Post
SongoQ
post 8.03.2007, 15:26:34
Post #4





Grupa: Przyjaciele php.pl
Postów: 2 923
Pomógł: 9
Dołączył: 25.10.2004
Skąd: Rzeszów - studia / Warszawa - praca

Ostrzeżenie: (0%)
-----


Mozesz odczytac zrodlo z bazy i stworzyc obiekt. Jest w manualu.


--------------------
Go to the top of the page
+Quote Post
vahooz
post 8.03.2007, 16:23:00
Post #5





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 28.05.2006

Ostrzeżenie: (0%)
-----


Czy mógłbyś mi pomóc bo naprawdę nie wiem jak to zrobić, szukam, czytam i się zastanawiam:
  1. <?php
  2.  
  3. $Id = "3";
  4. if(!isset($Id)) die("Need 'Id' parameter");
  5. else $Id=addslashes($Id);
  6. include("common.php");
  7.  
  8.  
  9. //set up SQL connection
  10. $link = mysql_connect ($server, $user, $password);
  11. if (! $link) die ("Couldn't connect to mySQL server");
  12. if (!mysql_select_db ($db, $link) ) die ("Coldn't open $db: ".mysql_error() );
  13.  
  14.  
  15. $query = "SELECT filetype, bin_data FROM tbl_Files WHERE id_files='$Id';";
  16. //$query = 'SELECT filetype, bin_data FROM tbl_Files WHERE id_files="1"';
  17. $result = mysql_query($query);
  18.  
  19.  
  20. $query_data = mysql_fetch_array($result);
  21. $bin_data = $query_data[bin_data];
  22. $filetype = $query_data[filetype];
  23.  
  24. Header("Content-type: $filetype");
  25.  
  26.  
  27. $filename = $bin_data;
  28.  
  29. $percent = 0.5;
  30.  
  31. header('Content-type: image/jpeg');
  32.  
  33. list($width, $height) = getimagesize($filename);
  34. echo "x".$new_width = $width * $percent;
  35. echo "y".$new_height = $height * $percent;
  36.  
  37. $image_p = imagecreatetruecolor($new_width, $new_height);
  38. $image = imagecreatefromjpeg($filename);
  39. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  40.  
  41.  
  42. echo imagejpeg($image_p, null, 100);
  43.  
  44. ?>


Pozdrawiam.


--------------------
shit, fuck and microsoft
Go to the top of the page
+Quote Post
SongoQ
post 8.03.2007, 17:30:17
Post #6





Grupa: Przyjaciele php.pl
Postów: 2 923
Pomógł: 9
Dołączył: 25.10.2004
Skąd: Rzeszów - studia / Warszawa - praca

Ostrzeżenie: (0%)
-----


  1. <?php
  2. $rPhoto = imagecreatefromstring('zrodlo obrazka pobrane z bazy');
  3. ?>


W $rPhoto masz obiekt obrazka i dalej robisz tak jak Ci podawalem na samym poczatku.


--------------------
Go to the top of the page
+Quote Post
vahooz
post 8.03.2007, 18:13:30
Post #7





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 28.05.2006

Ostrzeżenie: (0%)
-----


  1. <?php
  2. $Id = "3";
  3. if(!isset($Id)) die("Need 'Id' parameter");
  4. else $Id=addslashes($Id);
  5. include("common.php");
  6. $link = mysql_connect ($server, $user, $password);
  7. if (! $link) die ("Couldn't connect to mySQL server");
  8. if (!mysql_select_db ($db, $link) ) die ("Coldn't open $db: ".mysql_error() );
  9. $query = "SELECT filetype, bin_data FROM tbl_Files WHERE id_files='$Id';";
  10. $result = mysql_query($query);
  11. $query_data = mysql_fetch_array($result);
  12. $bin_data = $query_data[bin_data];
  13. $filetype = $query_data[filetype];
  14. Header("Content-type: $filetype");
  15. //echo $bin_data; //TU JEST OK WYSWIETLA OBRAZEM
  16. $filename = imagecreatefromstring($bin_data);
  17. $percent = 0.5;
  18. list($width, $height) = getimagesize($filename);
  19. $new_width = $width * $percent;
  20. $new_height = $height * $percent;
  21. $image_p = imagecreatetruecolor($new_width, $new_height);
  22. $image = imagecreatefromjpeg($filename);
  23. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  24. imagejpeg($image_p, null, 100);
  25. imagedestroy($image_p);
  26. ?>


Niestety nic nie wyświetla, podstawiając pod $filename nazwę pliku na serwerze to działa. Jednak tworząc obraz za pomocą imagecreatefromstring($bin_data) nie działa. Z manuala dorwałem gotowca, który tez nie działa!!
  1. <?php
  2. require("dbconfig.inc");
  3.  
  4. $id = $_GET['id'];
  5.  
  6. if($id) {
  7.  
  8.  $link = @mysql_connect($host, $user, $password) or die("Could not connect: " . mysql_error());
  9.  @mysql_select_db($dbname, $link);
  10.  
  11.  $query = "select filetype, image from pictures where id = $id";
  12.  $result = @mysql_query($query);
  13.  
  14.  $data = @mysql_result($result,0,"image");
  15.  $type = @mysql_result($result,0,"filetype");
  16.  
  17.  Header( "Content-type: $type");  
  18.  
  19.  $size = 150; // new image width
  20.  $src = imagecreatefromstring($data);
  21.  $width = imagesx($src);
  22.  $height = imagesy($src);
  23.  $aspect_ratio = $height/$width;
  24.  
  25.  if ($width <= $size) {
  26.  $new_w = $width;
  27.  $new_h = $height;
  28.  } else {
  29.  $new_w = $size;
  30.  $new_h = abs($new_w * $aspect_ratio);
  31.  }
  32.  
  33.  $img = imagecreatetruecolor($new_w,$new_h);
  34.  imagecopyresized($img,$src,0,0,0,0,$new_w,$new_h,$width,$height);
  35.  
  36.  // determine image type and send it to the client  
  37.  if ($type == "image/pjpeg") {  
  38.  imagejpeg($img);
  39.  } else if ($type == "image/x-png") {
  40.  imagepng($img);
  41.  } else if ($type == "image/gif") {
  42.  imagegif($img);
  43.  }
  44.  imagedestroy($img);
  45.  mysql_close($link);
  46. };
  47. ?>

Czy to możliwe, że mam jakieś ograniczenia po stronie serwera?


--------------------
shit, fuck and microsoft
Go to the top of the page
+Quote Post
SongoQ
post 8.03.2007, 20:53:19
Post #8





Grupa: Przyjaciele php.pl
Postów: 2 923
Pomógł: 9
Dołączył: 25.10.2004
Skąd: Rzeszów - studia / Warszawa - praca

Ostrzeżenie: (0%)
-----


Calkiem mozliwe, jakies bledy wyrzuca? Wlacz raportowanie bledow i pokaz co CI pokazalo.


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 10:36