Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating new image

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I have the following code which creates a thumbnail image from a larger picture.
Code:
<?php
$img_name=$_GET['imnam'];
$new_lname=$_GET['nlnam'];
$new_sname=$_GET['nsnam'];
$max_width    = 150; // maximum x aperture  in pixels
$max_height   = 150; // maximum y aperture in pixels
$size=GetImageSize($img_name);
$width_ratio  = ($size[0] / $max_width);
$height_ratio = ($size[1] / $max_height);
 
if($width_ratio >=$height_ratio) 
{
   $ratio = $width_ratio;
}
else
{
   $ratio = $height_ratio;
}
$new_width    = ($size[0] / $ratio);
$new_height   = ($size[1] / $ratio);

$src_img = ImageCreateFromJPEG($img_name);
$thumb = ImageCreateTrueColor($new_width,$new_height);
ImageCopyResampled($thumb, $src_img, 0,0,0,0,($new_width-1),($new_height-1),$size[0],$size[1]);

$textcolor = imagecolorallocate($thumb, 255, 0, 0);
$textcolor2 = imagecolorallocate($thumb, 0, 0, 0);

imagestring($thumb, 3, $new_width-$max_width, $new_height-30, "FUMNAIL FUMNAIL", $textcolor);
imagestring($thumb, 3, $new_width-$max_width, $new_height-120, "FUMNAIL FUMNAIL", $textcolor2);
ImageJPEG($thumb);
ImageDestroy($src_img);
ImageDestroy($thumb);
?>

All ok and working up to here
but I want to create a new file on the server
so I change the last part to what the tutorial says
Code:
ImageJPEG($thumb,[b]"newpic.jpg"[/b]);
ImageDestroy($src_img);
ImageDestroy($thumb);
?>
I have tried a whole manner of options but the new file is not created.
I don't think it is a permission issue as the file is uploaded just before this script is run.
Could someone tell me what I am missing?

Keith
 
It might be a permission issue issue with the folder you are trying to create the image in.

When the image is uploaded it is uploaded to a temp folder elsewhere on the server (defined by the host). But you need the server engine to have write permissions to the folder where you are trying to write the image into...which is no longer the temp folder.

If you are running Apache you'll need to set your folder permission to 0777...and I'm not sure what it would be for IIS since I don't really use it.

***************************************
J. Jacobs
 
If you are running Apache you'll need to set your folder permission to 0777...and I'm not sure what it would be for IIS since I don't really use it.

this is only true if you are running a *nix system. and it is not necessary to open the directory that much. apache tends to run under linux as "nobody". you should just give the nobody user the minimum permissions necessary on the relevant directory. 0777 is all permissions.

on windows platforms IIS will run typically as IUSR_[machine_name] and you specify the user rights for apache at the time you install it (from memory).

ggggus is right, however, that it is likely to be a permissions issue.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top