GD + Mysql

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-26-2003
Damien Viel
 
Posts: n/a
Default 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
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


Reply With Quote
  #2 (permalink)  
Old 11-26-2003
Juha Suni
 
Posts: n/a
Default Re: GD + Mysql

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



Reply With Quote
  #3 (permalink)  
Old 11-26-2003
Damien Viel
 
Posts: n/a
Default Re: GD + Mysql

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
>
>
>



Reply With Quote
  #4 (permalink)  
Old 11-26-2003
Johan Holst Nielsen
 
Posts: n/a
Default Re: GD + Mysql

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

Reply With Quote
  #5 (permalink)  
Old 11-26-2003
Damien Viel
 
Posts: n/a
Default 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@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
>



Reply With Quote
  #6 (permalink)  
Old 11-26-2003
Jedi121
 
Posts: n/a
Default Re: GD + Mysql

Answered on alt.comp.lang.php...
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...


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:04 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0