[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

PHP image resize that makes the resulting image download to user's computer and redirects to new page.

Asked by Chiselneck in PHP Scripting Language, Miscellaneous Web Development, PHP and Databases

Tags: php, image, resize, html

How can I made this code used to resize an image to 40 pixels wide... make the resulting image download to the user's computer, so they can save it to their hard drive and not on our server?

Also is there a method to have the user redirected to another page once the file has been converted?
Thanks.


Here's the code for the HTML page:

=====================================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Resize to 40 pixels wide</title>
<style type="text/css">
<!--
.style1 {
      font-family: "Trebuchet MS";
      color: #666666;
      font-size: 14px;
}
.style3 {font-size: 18px;
      color: #333333;
}
-->
</style>
</head>

<body>
<span class="style1"><span class="style3">Resize your images to 40 Pixels wide.</span><br />
Click browse below, locate the image you wish to resize and click Submit.<br />
<br />
</span>
<form action="upload.php" method="post" enctype="multipart/form-data" class="style1" >
<input type="file" name="uploadfile"/>
<input type="submit"/>
</form>
</body>
</html>
=================================
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
<?php
 
// This is the temporary file created by PHP 
$uploadedfile = $_FILES['uploadfile']['tmp_name'];
 
// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);
 
// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);
 
// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect 
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
$newwidth=40;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
 
// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
 
// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = "resized/". $_FILES['uploadfile']['name'];
imagejpeg($tmp,$filename,100);
 
imagedestroy($src);
imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
// has completed.
?>
[+][-]03/28/09 12:11 AM, ID: 24007526Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/28/09 07:49 AM, ID: 24008718Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: PHP Scripting Language, Miscellaneous Web Development, PHP and Databases
Tags: php, image, resize, html
Sign Up Now!
Solution Provided By: MasonWolf
Participating Experts: 2
Solution Grade: A
 
[+][-]03/28/09 11:44 AM, ID: 24009601Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/28/09 12:38 PM, ID: 24009812Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/28/09 12:42 PM, ID: 24009828Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_Related_20080208