Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Resizing Image Before Uploading
Old 07-04-2010, 03:02 AM Resizing Image Before Uploading
Skilled Talker

Posts: 83
Trades: 0
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:
PHP 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$source0000$newwidth$newheight$width$height);

// Output
imagegif($thumb); 
Smudly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-04-2010, 05:57 AM Re: Resizing Image Before Uploading
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Isn't going to happen with PHP which runs on the server, so until the image is uploaded it does not exist for PHP.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-06-2010, 08:42 PM Re: Resizing Image Before Uploading
Skilled Talker

Posts: 83
Trades: 0
Alright, well once the image is uploaded to the server, how can I change the size of that image so the images aren't taking as much space?
Smudly is offline
Reply With Quote
View Public Profile
 
Old 07-06-2010, 08:53 PM Re: Resizing Image Before Uploading
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
HTTP/HTML form uploads the image

Apache stores the uploaded image into a temp directory

PHP reads the image file into memory using GD image functions

PHP resizes the image using GD image functions

PHP writes a new image file to a permanate location on the web server using GD image functions

(optional) PHP unlinks the temp uploaded image file
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-10-2010, 09:47 AM Re: Resizing Image Before Uploading
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
if you have imagemagick installed:
PHP Code:
$infile $_FILES['userfile']['tmp_name']; // or whatever
$outfile "/path/to/userpics/userpic.jpg"// or whatever
$cmd "convert '{$infile}' -scale '65x65>' -quality 90 '{$outfile}'";
exec($cmd); 
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Resizing Image Before Uploading
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.45330 seconds with 12 queries