This is a discussion on GD + Mysql within the PHP Language forums, part of the PHP Programming Forums category; Bonjour à tous. J'essaie de redimensionner une image qui est stockée dans une table MySQL mais j'obtiens une ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 imagecreatefromjpeg(), getimagesize() et imagecopyresized() . 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($res,0,pics); $srcImg = imagecreatefromjpeg($temp); $srcSize = getimagesize($temp); $dstImg = imagecreatetruecolor(50,50); imagecopyresized($dstImg, $srcImg, 0, 0, 0, 0, 50, 50, $srcSize[0], $srcSize[1]); imagejpeg($dstImg); imagedestroy($scrImg); imagedestroy($dstImg); } } ?> Merci. Damien -- # Damien Viel # damien@studioclick.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 |
|
|||
|
Damien Viel wrote:
> Bonjour à tous. Hi. > > 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 imagecreatefromjpeg(), getimagesize() et imagecopyresized() > . 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 > ? 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 imagecreatefromjpeg(), getimagesize() and imagecopyresized(). 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? " > <?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($res,0,pics); > $srcImg = imagecreatefromjpeg($temp); > $srcSize = getimagesize($temp); > $dstImg = imagecreatetruecolor(50,50); > imagecopyresized($dstImg, $srcImg, 0, 0, 0, 0, 50, 50, > $srcSize[0], $srcSize[1]); > imagejpeg($dstImg); > imagedestroy($scrImg); > imagedestroy($dstImg); > } > } Im not an expert with the GD library, since I've found ImageMagick to be so much better. Others feel free to comment. -- Suni |
|
|||
|
Ok Thanks,
Sorry for the language.... Next time I will try in English. Bests Damien -- # Damien Viel # damien@studioclick.fr # http://www.studioclick.fr "Juha Suni" <juha.suni@ilmiantajat.fi> a écrit dans le message de news:3fc4ab8e$0$14398$39db0f71@news.song.fi... > Damien Viel wrote: > > Bonjour à tous. > > Hi. > > > > > 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 imagecreatefromjpeg(), getimagesize() et imagecopyresized() > > . 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 > > ? > > 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 > imagecreatefromjpeg(), getimagesize() and imagecopyresized(). 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? " > > > > <?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($res,0,pics); > > $srcImg = imagecreatefromjpeg($temp); > > $srcSize = getimagesize($temp); > > $dstImg = imagecreatetruecolor(50,50); > > imagecopyresized($dstImg, $srcImg, 0, 0, 0, 0, 50, 50, > > $srcSize[0], $srcSize[1]); > > imagejpeg($dstImg); > > imagedestroy($scrImg); > > imagedestroy($dstImg); > > } > > } > > Im not an expert with the GD library, since I've found ImageMagick to be > so much better. Others feel free to comment. > > -- > Suni > > > |
|
|||
|
Juha Suni wrote:
> 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 > imagecreatefromjpeg(), getimagesize() and imagecopyresized(). 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? " Thansk for the translation ;) > > >><?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($res,0,pics); >> $srcImg = imagecreatefromjpeg($temp); >> $srcSize = getimagesize($temp); >> $dstImg = imagecreatetruecolor(50,50); >> imagecopyresized($dstImg, $srcImg, 0, 0, 0, 0, 50, 50, >>$srcSize[0], $srcSize[1]); >> imagejpeg($dstImg); >> imagedestroy($scrImg); >> imagedestroy($dstImg); >> } >>} Try something like... <?php if(isset($id)) { require("./conf/config.inc.php"); $result = mysql_query("SELECT * FROM images WHERE id = $id"); if(mysql_num_rows($result)>0) { $tmpName = tempnam("/tmp", "IMAGE_"); $tmp = fopen($tmpName,"w"); fwrite($tmp,mysql_result($res,0,pics)); fclose($tmp); $tmpSize = getImageSize($tmp); $srcImg = imagecreatefromjpeg($tmpName); $dstImg = imagecreatetruecolor(50,50); imagecopyresized($dstImg,$srcImg,0,0,0,0,50,50,$tm pSize[0],tmpSize[1]); header("Content-Type: image/jpg"); imagejpeg($dstImg); imagedestroy($dstImg); imagedestroy($srcImg); 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 |
|
|||
|
Thanks,
Yes that should work, but it may have some trouble if the safe mode is enabled. Bests Dams -- # Damien Viel # damien@studioclick.fr # http://www.studioclick.fr "Johan Holst Nielsen" <johan@weknowthewayout.com> a écrit dans le message de news:3fc4ce2a$0$9803$edfadb0f@dread14.news.tele.dk ... > Juha Suni wrote: > > 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 > > imagecreatefromjpeg(), getimagesize() and imagecopyresized(). 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? " > > Thansk for the translation ;) > > > > > > >><?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($res,0,pics); > >> $srcImg = imagecreatefromjpeg($temp); > >> $srcSize = getimagesize($temp); > >> $dstImg = imagecreatetruecolor(50,50); > >> imagecopyresized($dstImg, $srcImg, 0, 0, 0, 0, 50, 50, > >>$srcSize[0], $srcSize[1]); > >> imagejpeg($dstImg); > >> imagedestroy($scrImg); > >> imagedestroy($dstImg); > >> } > >>} > > Try something like... > > <?php > if(isset($id)) { > require("./conf/config.inc.php"); > $result = mysql_query("SELECT * FROM images WHERE id = $id"); > if(mysql_num_rows($result)>0) { > $tmpName = tempnam("/tmp", "IMAGE_"); > $tmp = fopen($tmpName,"w"); > fwrite($tmp,mysql_result($res,0,pics)); > fclose($tmp); > $tmpSize = getImageSize($tmp); > $srcImg = imagecreatefromjpeg($tmpName); > $dstImg = imagecreatetruecolor(50,50); > imagecopyresized($dstImg,$srcImg,0,0,0,0,50,50,$tm pSize[0],tmpSize[1]); > header("Content-Type: image/jpg"); > imagejpeg($dstImg); > imagedestroy($dstImg); > imagedestroy($srcImg); > 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 > |