LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-07-2005, 12:06 AM   #1
benrose111488
Member
 
Registered: Jun 2004
Location: Wantage, NJ
Distribution: Fedora 7
Posts: 177

Rep: Reputation: 30
PHP image handling/resizing


hello... I'm writing a PHP script that needs to take an image and trash the quality level until the filesize is 512k or less

I've written the following code:
PHP Code:
$fileContent imap_base64(imap_fetchbody($mbox,$msgno,'2'));
$newfilename=get_new_filename($suffix0);
while(
file_exists($newfilename))
{
$newfilename=get_new_filename($suffix0);}
$newfilenametemp=get_new_filename($suffix1);
while(
file_exists($newfilenametemp))
{
$newfilenametemp=get_new_filename($suffix1);}
$fdtemp fopen($newfilenametemp'w');
fwrite($fdtemp$fileContent);
fclose($fdtemp);
$fd fopen($newfilename'w');
imagejpeg($newfilenametemp$fd75);
fclose($fd);

function 
get_new_filename($suffix$temp)
{
srand(time());
$random = (rand()%999999999999999999);
if(
$temp == "0")
{
$newfilename "/home/scavenger/scavengerxhunt.com/subimgdir/" $random "" $suffix;}
elseif(
$temp == "1")
{
$newfilename "/home/scavenger/scavengerxhunt.com/subimgdir/" $random "temp" $suffix;}
return 
$newfilename;

however, this code always leads to the following error:
Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/.elysium/scavenger/scavengerxhunt.com/getmail.php on line 105

apparently the image itself on the server isn't a valid resource

any ideas what's going wrong? I've heard of using imagecreatetruecolor() but I have no idea how or why to use it

please assist...
 
Old 07-07-2005, 03:00 AM   #2
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

Rep: Reputation: 136Reputation: 136
imagejpeg is defined as :
PHP Code:
bool imagejpeg resource image [, string filename [, int quality]] ) 
So try replace :
PHP Code:
$fd fopen($newfilename'w');
imagejpeg($newfilenametemp$fd75);
fclose($fd); 
with :
PHP Code:
$im imagecreatefromstring ($fileContent);
imagejpeg($im$newfilenametemp75);
imageDestroy($im); 
[edit]
Or write content directly as you did with $fdtemp
PHP Code:
$fd fopen($newfilename'w');
fwrite($fd$fileContent);
fclose($fd); 

Last edited by keefaz; 07-07-2005 at 03:24 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resizing a loopback image Jehuty Linux - Hardware 5 08-29-2005 11:52 AM
Image resizing algorithms R00ts Programming 1 07-05-2004 01:56 PM
Handling filenames with spaces in PHP gw1500se Programming 2 03-14-2004 02:03 PM
handling downloads with php niehls Programming 0 02-09-2003 06:11 AM
PHP Link Handling Citizen Bleys Programming 1 10-10-2001 04:02 PM


All times are GMT -5. The time now is 09:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration