GD + Mysql

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Damien Viel

    GD + Mysql


    Bonjour à tous.

    J'essaie de redimensionner une image qui est stockée dans une table MySQL
    mais j'obtiens une erreur lorsque je passe ma variable aux fonctions
    imagecreatefrom jpeg(), getimagesize() et imagecopyresize d() . Il faut leurs
    passer un fichier et non une variable mémoire. Mais je n'ai pas envie de
    creer des fichiers pour faire cela, même temporairement. Je doit travailler
    en memoire. Qq a-t-il une solution ?

    <?php
    if (isset($id)) {
    require ("./conf/config.inc.php" );
    $res = mysql_query ("SELECT * FROM images WHERE id=$id");
    if (mysql_num_rows ($res)>0) {
    header( "Content-Type: image/jpg");
    $temp = mysql_result($r es,0,pics);
    $srcImg = imagecreatefrom jpeg($temp);
    $srcSize = getimagesize($t emp);
    $dstImg = imagecreatetrue color(50,50);
    imagecopyresize d($dstImg, $srcImg, 0, 0, 0, 0, 50, 50, $srcSize[0],
    $srcSize[1]);
    imagejpeg($dstI mg);
    imagedestroy($s crImg);
    imagedestroy($d stImg);
    }
    }
    ?>
    Merci.
    Damien
    --
    # Damien Viel
    # damien@studiocl ick.fr
    # http://www.studioclick.fr


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.543 / Virus Database: 337 - Release Date: 21/11/2003


  • Juha Suni

    #2
    Re: GD + Mysql

    Damien Viel wrote:[color=blue]
    > Bonjour à tous.[/color]

    Hi.
    [color=blue]
    >
    > J'essaie de redimensionner une image qui est stockée dans une table
    > MySQL mais j'obtiens une erreur lorsque je passe ma variable aux
    > fonctions imagecreatefrom jpeg(), getimagesize() et imagecopyresize d()
    > . Il faut leurs passer un fichier et non une variable mémoire. Mais
    > je n'ai pas envie de creer des fichiers pour faire cela, même
    > temporairement. Je doit travailler en memoire. Qq a-t-il une solution
    > ?[/color]

    I have absolutely no idea what that could possibly mean. Most of us read
    and write good english here, but only a few possibly do so in French.

    From the above babelfish gives:
    " test redimensionner an image which is stored in a MySQL table but I
    obtain an error when I pass my variable to the functions
    imagecreatefrom jpeg(), getimagesize() and imagecopyresize d(). It is
    necessary their to pass a file and not a variable memory. But I do not
    want of creer files to do that, even temporarily. I must work in memory.
    Does Qq have a solution? "

    [color=blue]
    > <?php
    > if (isset($id)) {
    > require ("./conf/config.inc.php" );
    > $res = mysql_query ("SELECT * FROM images WHERE id=$id");
    > if (mysql_num_rows ($res)>0) {
    > header( "Content-Type: image/jpg");
    > $temp = mysql_result($r es,0,pics);
    > $srcImg = imagecreatefrom jpeg($temp);
    > $srcSize = getimagesize($t emp);
    > $dstImg = imagecreatetrue color(50,50);
    > imagecopyresize d($dstImg, $srcImg, 0, 0, 0, 0, 50, 50,
    > $srcSize[0], $srcSize[1]);
    > imagejpeg($dstI mg);
    > imagedestroy($s crImg);
    > imagedestroy($d stImg);
    > }
    > }[/color]

    Im not an expert with the GD library, since I've found ImageMagick to be
    so much better. Others feel free to comment.

    --
    Suni



    Comment

    • Damien Viel

      #3
      Re: GD + Mysql

      Ok Thanks,

      Sorry for the language....
      Next time I will try in English.

      Bests

      Damien

      --
      # Damien Viel
      # damien@studiocl ick.fr
      # http://www.studioclick.fr
      "Juha Suni" <juha.suni@ilmi antajat.fi> a écrit dans le message de
      news:3fc4ab8e$0 $14398$39db0f71 @news.song.fi.. .[color=blue]
      > Damien Viel wrote:[color=green]
      > > Bonjour à tous.[/color]
      >
      > Hi.
      >[color=green]
      > >
      > > J'essaie de redimensionner une image qui est stockée dans une table
      > > MySQL mais j'obtiens une erreur lorsque je passe ma variable aux
      > > fonctions imagecreatefrom jpeg(), getimagesize() et imagecopyresize d()
      > > . Il faut leurs passer un fichier et non une variable mémoire. Mais
      > > je n'ai pas envie de creer des fichiers pour faire cela, même
      > > temporairement. Je doit travailler en memoire. Qq a-t-il une solution
      > > ?[/color]
      >
      > I have absolutely no idea what that could possibly mean. Most of us read
      > and write good english here, but only a few possibly do so in French.
      >
      > From the above babelfish gives:
      > " test redimensionner an image which is stored in a MySQL table but I
      > obtain an error when I pass my variable to the functions
      > imagecreatefrom jpeg(), getimagesize() and imagecopyresize d(). It is
      > necessary their to pass a file and not a variable memory. But I do not
      > want of creer files to do that, even temporarily. I must work in memory.
      > Does Qq have a solution? "
      >
      >[color=green]
      > > <?php
      > > if (isset($id)) {
      > > require ("./conf/config.inc.php" );
      > > $res = mysql_query ("SELECT * FROM images WHERE id=$id");
      > > if (mysql_num_rows ($res)>0) {
      > > header( "Content-Type: image/jpg");
      > > $temp = mysql_result($r es,0,pics);
      > > $srcImg = imagecreatefrom jpeg($temp);
      > > $srcSize = getimagesize($t emp);
      > > $dstImg = imagecreatetrue color(50,50);
      > > imagecopyresize d($dstImg, $srcImg, 0, 0, 0, 0, 50, 50,
      > > $srcSize[0], $srcSize[1]);
      > > imagejpeg($dstI mg);
      > > imagedestroy($s crImg);
      > > imagedestroy($d stImg);
      > > }
      > > }[/color]
      >
      > Im not an expert with the GD library, since I've found ImageMagick to be
      > so much better. Others feel free to comment.
      >
      > --
      > Suni
      >
      >
      >[/color]


      Comment

      • Johan Holst Nielsen

        #4
        Re: GD + Mysql

        Juha Suni wrote:[color=blue]
        > Damien Viel wrote:
        > I have absolutely no idea what that could possibly mean. Most of us read
        > and write good english here, but only a few possibly do so in French.
        >
        > From the above babelfish gives:
        > " test redimensionner an image which is stored in a MySQL table but I
        > obtain an error when I pass my variable to the functions
        > imagecreatefrom jpeg(), getimagesize() and imagecopyresize d(). It is
        > necessary their to pass a file and not a variable memory. But I do not
        > want of creer files to do that, even temporarily. I must work in memory.
        > Does Qq have a solution? "[/color]

        Thansk for the translation ;)
        [color=blue]
        >
        >[color=green]
        >><?php
        >>if (isset($id)) {
        >> require ("./conf/config.inc.php" );
        >> $res = mysql_query ("SELECT * FROM images WHERE id=$id");
        >> if (mysql_num_rows ($res)>0) {
        >> header( "Content-Type: image/jpg");
        >> $temp = mysql_result($r es,0,pics);
        >> $srcImg = imagecreatefrom jpeg($temp);
        >> $srcSize = getimagesize($t emp);
        >> $dstImg = imagecreatetrue color(50,50);
        >> imagecopyresize d($dstImg, $srcImg, 0, 0, 0, 0, 50, 50,
        >>$srcSize[0], $srcSize[1]);
        >> imagejpeg($dstI mg);
        >> imagedestroy($s crImg);
        >> imagedestroy($d stImg);
        >> }
        >>}[/color][/color]

        Try something like...

        <?php
        if(isset($id)) {
        require("./conf/config.inc.php" );
        $result = mysql_query("SE LECT * FROM images WHERE id = $id");
        if(mysql_num_ro ws($result)>0) {
        $tmpName = tempnam("/tmp", "IMAGE_");
        $tmp = fopen($tmpName, "w");
        fwrite($tmp,mys ql_result($res, 0,pics));
        fclose($tmp);
        $tmpSize = getImageSize($t mp);
        $srcImg = imagecreatefrom jpeg($tmpName);
        $dstImg = imagecreatetrue color(50,50);
        imagecopyresize d($dstImg,$srcI mg,0,0,0,0,50,5 0,$tmpSize[0],tmpSize[1]);
        header("Content-Type: image/jpg");
        imagejpeg($dstI mg);
        imagedestroy($d stImg);
        imagedestroy($s rcImg);
        unlink($tmpName );
        }
        }

        ?>


        I have just made this fast... dont know if it work? :( I wont be back
        before tomorrow... if there are any problems just contact me (maybe by
        mail (tcr480 (at) yahoo (dot) dk

        Regards,
        Johan

        Comment

        • Damien Viel

          #5
          Re: GD + Mysql

          Thanks,

          Yes that should work, but it may have some trouble if the safe mode is
          enabled.
          Bests

          Dams

          --
          # Damien Viel
          # damien@studiocl ick.fr
          # http://www.studioclick.fr
          "Johan Holst Nielsen" <johan@weknowth ewayout.com> a écrit dans le message de
          news:3fc4ce2a$0 $9803$edfadb0f@ dread14.news.te le.dk...[color=blue]
          > Juha Suni wrote:[color=green]
          > > Damien Viel wrote:
          > > I have absolutely no idea what that could possibly mean. Most of us read
          > > and write good english here, but only a few possibly do so in French.
          > >
          > > From the above babelfish gives:
          > > " test redimensionner an image which is stored in a MySQL table but I
          > > obtain an error when I pass my variable to the functions
          > > imagecreatefrom jpeg(), getimagesize() and imagecopyresize d(). It is
          > > necessary their to pass a file and not a variable memory. But I do not
          > > want of creer files to do that, even temporarily. I must work in memory.
          > > Does Qq have a solution? "[/color]
          >
          > Thansk for the translation ;)
          >[color=green]
          > >
          > >[color=darkred]
          > >><?php
          > >>if (isset($id)) {
          > >> require ("./conf/config.inc.php" );
          > >> $res = mysql_query ("SELECT * FROM images WHERE id=$id");
          > >> if (mysql_num_rows ($res)>0) {
          > >> header( "Content-Type: image/jpg");
          > >> $temp = mysql_result($r es,0,pics);
          > >> $srcImg = imagecreatefrom jpeg($temp);
          > >> $srcSize = getimagesize($t emp);
          > >> $dstImg = imagecreatetrue color(50,50);
          > >> imagecopyresize d($dstImg, $srcImg, 0, 0, 0, 0, 50, 50,
          > >>$srcSize[0], $srcSize[1]);
          > >> imagejpeg($dstI mg);
          > >> imagedestroy($s crImg);
          > >> imagedestroy($d stImg);
          > >> }
          > >>}[/color][/color]
          >
          > Try something like...
          >
          > <?php
          > if(isset($id)) {
          > require("./conf/config.inc.php" );
          > $result = mysql_query("SE LECT * FROM images WHERE id = $id");
          > if(mysql_num_ro ws($result)>0) {
          > $tmpName = tempnam("/tmp", "IMAGE_");
          > $tmp = fopen($tmpName, "w");
          > fwrite($tmp,mys ql_result($res, 0,pics));
          > fclose($tmp);
          > $tmpSize = getImageSize($t mp);
          > $srcImg = imagecreatefrom jpeg($tmpName);
          > $dstImg = imagecreatetrue color(50,50);
          >[/color]
          imagecopyresize d($dstImg,$srcI mg,0,0,0,0,50,5 0,$tmpSize[0],tmpSize[1]);[color=blue]
          > header("Content-Type: image/jpg");
          > imagejpeg($dstI mg);
          > imagedestroy($d stImg);
          > imagedestroy($s rcImg);
          > unlink($tmpName );
          > }
          > }
          >
          > ?>
          >
          >
          > I have just made this fast... dont know if it work? :( I wont be back
          > before tomorrow... if there are any problems just contact me (maybe by
          > mail (tcr480 (at) yahoo (dot) dk
          >
          > Regards,
          > Johan
          >[/color]


          Comment

          • Jedi121

            #6
            Re: GD + Mysql

            Answered on alt.comp.lang.p hp...
            Please stop multiposting like this this is the 3rd copy of your
            original post I found!
            Learn how to crosspost and even better don't do it...


            Comment

            Working...