imagejpeg() unable to write to file error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

imagejpeg() unable to write to file error

Post by kendall »

Hello,

i have the following code:

[syntax=php]$image = imagecreatefromjpeg($url.'/'.$file);
$filename = explode('.',$file);
$imagesx = imagesx($image)/2;
$imagesy = imagesy($image)/2;
$thumbnail = imagecreate(100,100);
imagecopyresized($thumbnail,$image,0,0,$imagesx/2,$imagesy/2,100,100,100,100);
imagejpeg($thumbnail,$filename[0].'_alt.'.$filename[1],50);
imagedestroy($thumbnail);[/syntax]

on script debuggin i get a [quote]imagejpeg: unable to open 'band_image0_alt.jpg' for writing[/quote]

im am unsure as to what are the paramters to be for the imagejpeg() the documentation isnt specific what should be the paramaters?

Kendall
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

do you have write permissions on that directory?
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

AVATAr,

Yeah man i guess as the directory was newly created...the process is as follows :-

user creates a folder
user uploads file to folder
thumbnail is suppose to be created from file

note: directories are created umask(0); then mask(0777);
note: files were successfully uploaded even though no thumbs were created
note: thumnails files are renamed with an '_alt'
is file directory permissions the only reason why? what other reasons can there be

Kendall
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

if they create a directory, surely the save path of the thumbnail should include that directory name?

imagejpeg($thumbnail, $url. '/' .$filename[0]. '_alt.' .$filename[1], 80);

note: upped the 50 quality to 80 (at a compression setting of 50 you are going to get pretty nasty looking thumbs)
Also, if you are using GD2+ you should use imagecreatetruecolor and imagecopyresized to assure a palette greater than 256 indices.

Last note: If you are using GD2+ you could try the thumbnailing class from here - which would simplify the calls and assure proportional thumbnails within a bounding limit box. Can also add bevel, drop shadow, motion blur, greyscale etc etc
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

pootergeist,

why yes of course as it is the same path used to save the file (for a moment i was trying it url based thinking that was the problem) but tell me does it need the absolute path?

i acknowlgede you advice concerning the GD2+ i will look into it and c didnt no dat existed

doubt i have it (backward hosting)

Kendall
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

yo poo,

man that thing worked man....damn took what i was trying to do for weeks and summed it up in a one day script

thanks
Post Reply