Jump to content

Resizing Image Before Uploading


Smudly

Recommended Posts

Hi everyone,

 

I'm currently working on resizing an image that the user wants uploaded as their avatar. The resizing will occur before the uploading.

 

At the moment I'm just testing the resizing script without uploading it. It works great, however I need to make it so it will work with all image formats (at least the basics - jpg, png, gif, bmp). In the code below I tried changing the .jpeg and .jpg areas to .gif (abc.jpg Is Now abc.gif, image/jpeg Is Now image/gif, imagejpeg($thumb) is Now imagegif($thumb)), but it is giving me this error: "The image “http://www.mysite.com/testdelete.php” cannot be displayed, because it contains errors.".

The weird thing is, this error message is actually an image.

 

Am I going about this the right way? In the end, I will be needing to capture the resized picture in a variable to show to users on various pages. I noticed by using imagejpeg($thumb) it immediately shows it to the screen, but I would rather capture this into a variable to show in different areas of the page.

 

Any suggestions on where to go from here?

 

MySql Version 5.0.91

My Code:

// File and new size
$filename = 'avatars/abc.gif';

// Content type

header('Content-type: image/gif');



// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = 65;
$newheight = 65;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagegif($thumb);

Link to comment
https://forums.phpfreaks.com/topic/206685-resizing-image-before-uploading/
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.