PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 5th, 2004, 03:49 AM
bah26 bah26 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 18 bah26 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 29 sec
Reputation Power: 0
Store imagejpeg($var) as string....

Is there anyway I can store an image, created by imagejpeg as a variable as opposed to outputting to browser??

Example:
PHP Code:
<?php
$img 
imagecreatetruecolor(200200);
 
//DO NOT OUTPUT!! Store in $var....
imagejpeg($img); 
 
imagedestroy($img);
?>


Any ideas??


Cheers,

Ben

Reply With Quote
  #2  
Old August 5th, 2004, 05:08 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
Why do you want to? I'm not sure this is possible but we might be able to come up with an alternative for you.

-KM-

Reply With Quote
  #3  
Old August 5th, 2004, 10:23 AM
bah26 bah26 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 18 bah26 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 29 sec
Reputation Power: 0
Quote:
Originally Posted by kode_monkey
Why do you want to? I'm not sure this is possible but we might be able to come up with an alternative for you.

-KM-

I have a workaround, already... But it doesn't 'seem' like the best way...

<FONT color=#0000bb>
PHP Code:
<?php
$img 
imagecreatetruecolor(200200);
 
ob_start(); //Stdout --> buffer
 
imagejpeg($img); 

$img2 ob_get_contents(); //store stdout in $img2
 
ob_end_clean(); //clear buffer

imagedestroy($img); //destroy img
?>


Basically I'm generating images and storing them in a MySQL database.


(if your interested to why.....)
I'm generating semi-random* data to populate a database for testing.
Each entry requires an image, so I'm generating an image with a record name in the middle

*I say semi, because input is sensible(ish) - ie. it makes some sense.... its just not correct.


Ben

Reply With Quote
  #4  
Old August 5th, 2004, 12:27 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
You can always pass a second parameter to imagejpeg() that specifies a filename to write to and then store a reference to the filename or read the contents of the file after writing it and stick them in the db. The way you're doing it makes pretty good sense to me, though. Pretty smart, actually.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #5  
Old August 5th, 2004, 02:42 PM
bah26 bah26 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 18 bah26 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 29 sec
Reputation Power: 0
Quote:
Originally Posted by dhouston
You can always pass a second parameter to imagejpeg() that specifies a filename to write to and then store a reference to the filename or read the contents of the file after writing it and stick them in the db. The way you're doing it makes pretty good sense to me, though. Pretty smart, actually.

I unfortunately cannot take credit for this 'smart' way! I found the solution on the net.

Storing it is fine, but then you've got read/write issues, seems like a waste of resources.

I'll drop GD a message and see what they say.


Ben

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Store imagejpeg($var) as string....


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT