LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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-06-2005, 11:06 PM   #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, 02:00 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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 02:24 AM.
 
  


Reply



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 10:52 AM
Image resizing algorithms R00ts Programming 1 07-05-2004 12:56 PM
Handling filenames with spaces in PHP gw1500se Programming 2 03-14-2004 01:03 PM
handling downloads with php niehls Programming 0 02-09-2003 05:11 AM
PHP Link Handling Citizen Bleys Programming 1 10-10-2001 03:02 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:30 PM.

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
Open Source Consulting | Domain Registration