Jump to content

[SOLVED] Image Resize


Bricktop

Recommended Posts

Hello chaps,

 

Just a quick favour if I may?  I have a simple image upload script which I implemented for a friend.  However, the pictures they are uploading are really quite large and I would like my script to resize the image to 800 * 600 on upload.

 

I have tried to implement this but it's not working and I can't figure it out.  Below is the unmodified upload code:

 

function uploadImage()
{
global $settings;

		$path = $settings['uploadpath'];
		$filename = $_FILES['image']['name'];	
		$description = $_POST['description'];

	if ( $filename == "" )
	{	

		$content = '<font color="red">Please select a file to upload</font>';
		$time = 4;

	}
	else
	{
		move_uploaded_file( $_FILES['image']['tmp_name'] , $settings['uploadpath'] . $_FILES['image']['name'] );

		if (strlen($_FILES['image']['name']) > 0)
		{
			chmod($settings['uploadpath'] . $_FILES['image']['name'], 0644);
		}

 

Would someone be kind enough to repost my code with the relevant changes to make the script resize please?

 

Thanks very much.

Link to comment
https://forums.phpfreaks.com/topic/110387-solved-image-resize/
Share on other sites

Thanks for the link but this resize script simply resizes the dimensions of an image already held on the server.  It does not make the image any smaller in size.

 

What I want to do is resize the image as it is uploaded - so the image gets uploaded to the file server as the resized image, thus making a smaller file size.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/110387-solved-image-resize/#findComment-566332
Share on other sites

You can't resize the image before or "as it's uploaded" (as far as I know). The person would have to resize it themselves with an image app on their computer before uploading. The normal process is upload full image, resize & save as smaller.

 

The only thing I can think of is some Java app, which might be able to handle it all client side, but I'm not aware of anything like that.

Link to comment
https://forums.phpfreaks.com/topic/110387-solved-image-resize/#findComment-566510
Share on other sites

Thanks for the replies chaps - I got it working and it is possible to resize as the file is uploaded.

 

For those who may search the forums for an answer to a similar problem in future, please take a look at this excellent tutorial and code snippet here http://www.4wordsystems.com/php_image_resize.php.

 

Works a treat on my script!

Link to comment
https://forums.phpfreaks.com/topic/110387-solved-image-resize/#findComment-567114
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.