[PHP|MySQL] - Grafik auslesen



  • Hallo,

    kann mir jemand von euch SQL/WEB Profis sagen
    wie ich eine Grafik via PHP aus einem MySQL Blobfeld
    auslese und dieser via <img src="..."> darstelle.

    Bin für jede Hilfe dankbar 🙂
    Quelltext wäre auch nicht schlecht.

    Bye Peter.





  • Hab das noch nie gemacht, aber im Prinzip sollte das so gehen, dass du als src im <img>-Tag das PHP-Script angibst. In diesem liest du jetzt die Bilddaten aus der DB, sendest die entsprechenden Image-Header und anschließend die Bilddaten 🙂



  • normalerweise gibts nix an deiner art zu posten auszusetzen flenders aber wenn ich schon 2 links poste und du dann trotzdem noch "ich glaube" schreibst dann ist dir nicht zu helfen

    orginal von link2 kopiert :

    Here is the code I did to create a thumbnail image from the database blob field. The trick is to use "imagecreatefromstring()" to create an image file.
    
    Jack Shieh
    
    <?php
    require("dbconfig.inc");
    
    $id = $_GET['id'];
    
    if($id) {
    
        $link = @mysql_connect($host, $user, $password) or die("Could not connect: " . mysql_error());
        @mysql_select_db($dbname, $link);
    
        $query = "select filetype, image from pictures where id = $id";
        $result = @mysql_query($query);
    
        $data = @mysql_result($result,0,"image");
        $type = @mysql_result($result,0,"filetype");
    
        Header( "Content-type: $type");    
    
        $size = 150;  // new image width
        $src = imagecreatefromstring($data); 
        $width = imagesx($src);
        $height = imagesy($src);
        $aspect_ratio = $height/$width;
    
        if ($width <= $size) {
          $new_w = $width;
          $new_h = $height;
        } else {
          $new_w = $size;
          $new_h = abs($new_w * $aspect_ratio);
        }
    
        $img = imagecreatetruecolor($new_w,$new_h); 
        imagecopyresized($img,$src,0,0,0,0,$new_w,$new_h,$width,$height);
    
        // determine image type and send it to the client    
        if ($type == "image/pjpeg") {    
          imagejpeg($img); 
        } else if ($type == "image/x-png") {
          imagepng($img);
        } else if ($type == "image/gif") {
          imagegif($img);
        }
        imagedestroy($img); 
        mysql_close($link);
    };
    ?> 
    adrian_schmidt at yahoo dot com
    05-Mar-2003 10:04 
    I'm trying to get the imagecreatefromstring to work with GIFs. Of course, it won't.
    I've read the tips but can't get them to work either.
    The following is what I tried, based on above tips:
    
    ---
    
        header('Content-Type: image/gif');
        header('Content-Disposition: inline; filename=file.gif');
    
        $temp = tmpfile();
        fwrite($temp, $line['image']);
        $src_img = imagecreatefromgif($temp);
        fclose($temp); // this removes the file
        $dst_img = imagecreatetruecolor(100, 100);
        imagecopyresampled($dst_img, $src_img, 0,0,0,0, 100,100, imagesx($src_img), imagesy($src_img));
    
        imagegif($dst_img);
    
    ---
    
    where $line['image'] is the gif as taken from my MySQL database...
    
    If anyone that has been able to make something like this work could give me a working piece of code I'd be really greatful!
    
    I would be great if the tempfile could be excluded too...
    
    Below is a working piece of code for jpeg:
    
    ---
    
        header('Content-Type: image/jpeg');
        header('Content-Disposition: inline; filename=file.jpg');
    
        $src_img = imagecreatefromstring($line['image']);
        $dst_img = imagecreatetruecolor(100, 100);
        imagecopyresampled($dst_img, $src_img, 0,0,0,0, 100,100, imagesx($src_img), imagesy($src_img));
    
        imagejpeg($dst_img);
    


  • Dann hast du mich offenbar falsch verstanden! Ich wollte damit sagen, dass er afaik diese Funktionen gar nicht braucht, wenn er nichts mit PHP am Bild verändern will, sondern dass er in diesem Fall die Bilddaten, wie er sie ausgelesen hat direkt senden kann.

    BTW: wo habe ich in diesem Thread "ich glaube" geschrieben 😕



  • flenders schrieb:

    BTW: wo habe ich in diesem Thread "ich glaube" geschrieben 😕

    nirgens sonst hät ichs ja auch nicht "" gesetzt oO


Anmelden zum Antworten