can't get rid of temp image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
chopthewood

can't get rid of temp image

Post by chopthewood »

I have the following php script which works well except that a copy of the uploaded image always gets placed in the "php" directory as well as the two other specified locations (largeImages and thumbImages). How can I avoid this?
thanks

Code: Select all

<HTML>
<HEAD>
<TITLE>Successful File Upload</TITLE>
</HEAD>

<BODY>

<?


$largeImgName=$_FILES['imgLarge']['name'];

$thumbImgName=$largeImgName;
//

//

// ------------------------ IMAGE MAGICK ---------------------------



// Temporary upload image names
$originalLarge_image = $_FILES[imgLarge][tmp_name];
$originalThumb_image=$_FILES[imgLarge][tmp_name];
// set the jpg quality
$theQualityLarge=75;
$theQualityThumb=60;
// Get the image dimensions
$sizeLarge=GetImageSize( $originalLarge_image );
$sizeThumb=GetImageSize( $originalLarge_image );

// Maximum image width
$max_widthLarge = "450";
$max_widthThumb = "100";

// Maximum image height
$max_heightLarge = "450";
$max_widthThumb = "100";
//
// Resize the image and save


exec("convert -size {$sizeThumb[0]}x{$sizeThumb[1]}  $originalThumb_image -thumbnail {$max_widthThumb}x{$max_heightThumb} -quality $theQualityThumb $thumbImgName");
@copy( $originalThumb_image,"/home/jmt/public_html/thumbImages/".$thumbImgName) or die("Couldn't copy the Large image.");

exec("convert -size {$sizeLarge[0]}x{$sizeLarge[1]}  $originalLarge_image -thumbnail {$max_widthLarge}x{$max_heightLarge} -quality $theQualityLarge $largeImgName");
@copy($originalLarge_image,"/home/jmt/public_html/largeImages/".$largeImgName) or die("Couldn't copy the Large image.");


echo "<img src=\"".$largeImgName."\">";


?>


<H1>Success!</H1>

<P>You have uploaded the image: <b><? echo $_FILES[imgLarge][name]; ?>,</b> to your portfolio site.<br>
If you haven't already done so, be sure to create an information file about this artwork.


</BODY>
</HTML>
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: can't get rid of temp image

Post by Bonzo »

I presume as you are saving the image with ImageMagick then copying it that is the problem.

I would either unlink( ) the image created, use move instead of copy or preferably save directly to the finished destination folder.
chopthewood

Re: can't get rid of temp image

Post by chopthewood »

I'm using the @copy to copy directly to the destination directory. I don't know why it's also being copied to the php folder.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: can't get rid of temp image

Post by Bonzo »

What I am saying is why save the image and then copy it ? You should be able to save it directly to the final folder. This will remove one step as well.

Code: Select all

exec("convert -size {$sizeThumb[0]}x{$sizeThumb[1]}  $originalThumb_image -thumbnail {$max_widthThumb}x{$max_heightThumb} -quality $theQualityThumb /home/jmt/public_html/thumbImages/$thumbImgName");

exec("convert -size {$sizeLarge[0]}x{$sizeLarge[1]}  $originalLarge_image -thumbnail {$max_widthLarge}x{$max_heightLarge} -quality $theQualityLarge /home/jmt/public_html/largeImages/$largeImgName");
chopthewood

Re: can't get rid of temp image

Post by chopthewood »

thank you again, Bonzo. What I didn't realize was that within the "exec" parameters, the image was actually being saved to the server (there doesn't seem to be a 'save' command of any kind in there). I thought that it was simply resizing it and setting the quality, then I needed to @copy it after that. I am totally unfamiliar with command line stuff.
Anyway, that worked great and I appreciate this forum and others like it. They are so valuable to programmers of all levels.

:D
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: can't get rid of temp image

Post by Bonzo »

I am glad its sorted now; I did wonder why you insisted on using the @copy !

The trouble is I tend to forget the basics and think things like that are obvious.
Post Reply