By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,985 Members | 1,712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,985 IT Pros & Developers. It's quick & easy.

GD + Mysql

P: n/a

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
# da****@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
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

Jul 17 '05 #2

P: n/a
Ok Thanks,

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

Bests

Damien

--
# Damien Viel
# da****@studioclick.fr
# http://www.studioclick.fr
"Juha Suni" <ju*******@ilmiantajat.fi> a écrit dans le message de
news:3f***********************@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

Jul 17 '05 #3

P: n/a
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

Jul 17 '05 #4

P: n/a
Thanks,

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

Dams

--
# Damien Viel
# da****@studioclick.fr
# http://www.studioclick.fr
"Johan Holst Nielsen" <jo***@weknowthewayout.com> a écrit dans le message de
news:3f**********************@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

Jul 17 '05 #5

P: n/a
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...
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.