hi
i created a simple upload script which works fine and uploads image.
i m not involving validation at present. -
<?php
-
if($_FILES['photo']['name'])
-
{
-
echo $file_name = $_FILES['photo']['name'];
-
echo "<br>";
-
echo $file_tmp =$_FILES['photo']['tmp_name'];
-
-
move_uploaded_file($_FILES['photo']['tmp_name'], 'upload/'.$_FILES['photo']['name']);
-
}
-
?>
-
<!DOCTYPE html>
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-
<title>Untitled Document</title>
-
</head>
-
<body>
-
<form action="" method="post" enctype="multipart/form-data">
-
Your Photo: <input type="file" name="photo" size="25" />
-
<input type="submit" name="submit" value="Submit" />
-
</form>
-
</body>
-
</html>
-
now i have this code that resizes the image -
// The file
-
$filename = 'images/s1.jpg';
-
-
// Set a maximum height and width
-
$width = 200;
-
$height = 200;
-
-
// Content type
-
header('Content-Type: image/jpeg');
-
-
// Get new dimensions
-
list($width_orig, $height_orig) = getimagesize($filename);
-
-
$ratio_orig = $width_orig/$height_orig;
-
-
if ($width/$height > $ratio_orig) {
-
$width = $height*$ratio_orig;
-
} else {
-
$height = $width/$ratio_orig;
-
}
-
-
// Resample
-
$image_p = imagecreatetruecolor($width, $height);
-
$image = imagecreatefromjpeg($filename);
-
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
-
-
// Output
-
imagejpeg($image_p, null, 100);
-
so i tried to combine them as they both work fine independently -
<?php
-
if($_FILES['photo']['name'])
-
{
-
echo $file_name = $_FILES['photo']['name'];
-
echo "<br>";
-
echo $file_tmp =$_FILES['photo']['tmp_name'];
-
-
//resize function starts
-
$filename = 'images/'.$file_name;
-
-
// Set a maximum height and width
-
$width = 200;
-
$height = 200;
-
-
// Get new dimensions
-
list($width_orig, $height_orig) = getimagesize($filename);
-
-
$ratio_orig = $width_orig/$height_orig;
-
-
if ($width/$height > $ratio_orig) {
-
$width = $height*$ratio_orig;
-
} else {
-
$height = $width/$ratio_orig;
-
}
-
-
// Resample
-
$image_p = imagecreatetruecolor($width, $height);
-
$image = imagecreatefromjpeg($filename);
-
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
-
-
// Output
-
imagejpeg($image_p, null, 100);
-
// resize function ends
-
-
move_uploaded_file($_FILES['photo']['tmp_name'], 'upload/'.$_FILES['photo']['name']);
-
}
-
?>
-
<!DOCTYPE html>
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-
<title>Untitled Document</title>
-
</head>
-
<body>
-
<form action="" method="post" enctype="multipart/form-data">
-
Your Photo: <input type="file" name="photo" size="25" />
-
<input type="submit" name="submit" value="Submit" />
-
</form>
-
</body>
-
</html>
-
so i have two questions related to above combined code
1) The resample or resize function code will come before or after "move_uploaded_file" function ??
2) what will i write in the "move_uploaded_file" function so that resized thumbnail gets uploaded ??
vineet
0 1012 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jay |
last post by:
Hi guys, trying to fix a problem with an image resize routine. The code
posted below uploads and resizes a jpeg, probablem is, the outlook can look
a bit bitty becuase of teh samller size...is...
|
by: vunet.us |
last post by:
Hello,
What is the best image resizing tool is out there? I want to resize
images in ASP page when users upload them into some directory.
Your recommendations are super welcome.
Thank you.
|
by: atrus123 |
last post by:
Aloha all,
I'm trying to create a function that will create a thumbnail while preserving the aspect ratio. I had this working, but I made some changes and now the files are no longer being...
|
by: Shawn Northrop |
last post by:
Ive been searching for an image resize tutorial for a while now and found this code which worked nicely. I was unable to find the full source code but i think i pieced together the code from the...
|
by: Dominic Vella |
last post by:
Hi, I know I seem to have the really complicated questions, but I guess
that's why I'm here. This is a little verbose, only because I've been
trying to crack this for a week now.
Your help...
|
by: infoseekar |
last post by:
Image Resize & Rotation
Hi
I have 2 scripts, one for Image rotation and other image resize and they both are working.
Image resize scripts load the picture and resize it and Image rotation...
|
by: Noorain |
last post by:
Hi, another problem. i upload width=800 pixels image in database through. this image resize by thumb image & bis image. thumb image width is 100 pixel & big image width is 400 pixel. 800 pixel image...
|
by: simon2x1 |
last post by:
i have an image which width is 213 and height is 200 when
i echo the image and i resize it
echo "<img src='company/$present' width='70' height='68'/>";
the image was not as clear as when it was...
|
by: Nabeel Nazir |
last post by:
How can we write resize function for Matrix2 class;
where this function need to use Protected data members of matrix1 class?
Only setters are available in Matrix 1 class but there is no getter...
|
by: fran7 |
last post by:
Hi, I have this asp.net code to resize my images. It works fine although it resizes images without keeping the aspect ratio. My image display page is an .asp page extension.
I would rather keep...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |