hey guys - i need help with this code... currenty it just takes an
image and resize it to 450 by 337. What i need it to do is to make the
width 450, and just have the height be resized proptionally to widths
new lenght. Thanks!
if(!$bad_file_flag)
{
// filename will just be the current UNIX timestamp...
$fname = time() . $i;
$new_width = 450;
$new_height = 337;
// move_uploaded_file($_FILES[$element_name][tmp_name],
$vehicle_image_dir . "/$fname$file_extension");
// chmod($vehicle_image_dir . "/$fname$file_extension", 0666);
$tmp_image=imagecreatefromjpeg($_FILES[$element_name]['tmp_name']);
$width = imagesx($tmp_image);
$height = imagesy($tmp_image);
$new_image = imagecreatetruecolor($new_width,$new_height);
ImageCopyResized($new_image, $tmp_image,0,0,0,0, $new_width,
$new_height, $width, $height);
ImageJPEG($new_image,$vehicle_image_dir .
"/$fname$file_extension");
ImageDestroy($tmp_image);
ImageDestroy($new_image);
// move_uploaded_file($image_buffer, $vehicle_image_dir .
"/resized$fname$file_extension");
chmod($vehicle_image_dir . "/$fname$file_extension", 0666);
mysql_query("INSERT INTO dah_images (filename, vehicle_id)
VALUES('$fname$file_extension', $insert_id)");
}
else
{
// remove the bad file - we don't know what this is!
@unlink($_FILES[$element_name][tmp_name]);
} 8 3404
Get the current height & width of the image you are going to
manipulate.
Imagine it's 750 px wide, and 540 pixels high.
The new picture HAS to be 450 wide. 100% / 750 (original width) * 450
(new width) = 60 %, which means the new image will be 60% smaller.
New height = 540 (old height) / 100 % (gets 1 %) * 60 % (new
percentage) = 324
750 x 540 = 450 x 324.
All just a matter of maths... :D
Yeah i know how to do it mathematically but just have a hard time
making it into code...
hmm, sorry then, i must be missing something here...
i just don't know how to insert the code that you wrote into the code
that i have.... thanxs
First get the image size of the original image. http://php.net/getimagesize.
Transform that with my maths and then replace the following in your
code:
$new_width = 450;
$new_height = 337;
With:
$new_width = 450;
$new_height =
$the_new_height_i_showed_you;
If still not clear, ask! :D
Good luck with it.
so here is my problem
$new_width = 450;
$new_height = How do i transform the math
into code? i don't know the proper way to do it....
thanxs for the help
I haven't got any time today to help you out, but i'll have a look on
it on monday...
If i'm not mistaking, the following code should be ready to go:
if(!$bad_file_flag)
{
// define new width, and height will be calculated by itself
$new_width = 450;
// filename will just be the current UNIX timestamp...
$fname = time() . $i;
//
move_uploaded_file($_FILES[$element_name][tmp_name],$vehicle_image_dir
.. "/$fname$file_extension");
// chmod($vehicle_image_dir . "/$fname$file_extension", 0666);
$tmp_image =imagecreatefromjpeg($_FILES[$element_name]['tmp_name']);
$width = imagesx($tmp_image);
$height = imagesy($tmp_image);
$new_height = round(($height / 100) * (100 / $width * $new_width),
0);
$new_image = imagecreatetruecolor($new_width, $new_height);
ImageCopyResized($new_image, $tmp_image,0,0,0,0, $new_width,
$new_height, $width, $height);
ImageJPEG($new_image,$vehicle_image_dir ."/$fname$file_extension");
ImageDestroy($tmp_image);
ImageDestroy($new_image);
// move_uploaded_file($image_buffer, $vehicle_image_dir
.."/resized$fname$file_extension");
chmod($vehicle_image_dir . "/$fname$file_extension", 0666);
mysql_query("INSERT INTO dah_images (filename,
vehicle_id)VALUES('$fname$file_extension', $insert_id)");
}
else
{
// remove the bad file - we don't know what this is!
@unlink($_FILES[$element_name][tmp_name]);
}; This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sam Collett |
last post by:
How would you go about create a web control that allows you to upload
images and limit the dimensions (width/height) of the image? The
control may be put on any page, which may not contain the...
|
by: Neo Geshel |
last post by:
Greetings.
I am making an admin interface, which allows me to upload photos to an
access DB. The admin interface also needs to display the uploaded
photos, but only needs to show them at a...
|
by: Neo Geshel |
last post by:
I have examined about 80+ different upload scripts on the 'net, both in
VB and C#, and none seem to do what I need them to do. Perhaps someone
here can point me somewhere that Google hasn't...
|
by: Neo Geshel |
last post by:
Greetings.
I am making an admin interface, which allows me to upload photos to an
access DB. The admin interface also needs to display the uploaded
photos, but only needs to show them at a...
|
by: webonomic |
last post by:
Converting data types
I'm trying to do some image manipulation. This code project article
(http://www.codeproject.com/csharp/imageresize.asp) has a great method
I want to modefy. Here it is:
...
|
by: evolozik |
last post by:
hi everyone
i need some help please
i am using PHP5 and i used a tutorial and when i copied the code for Resampling an image proportionally, it worked perfectly
but when i added it in my page it...
|
by: tshad |
last post by:
Is there a way to display images (imageButtons or linkbuttons for instance)
as a max size (200px by 50px) and not have it stretch the image?
What I want to be able to do is limit the real estate...
|
by: barber.brad |
last post by:
We are code crushing the width of images from 285px to 260 pix.
However we aren't changing the height. we need a bit of javascript
that can make that percentage change to the height as well. Can...
|
by: Tony Sosa |
last post by:
Does anyone know what kind of tweaks I need to make to pertinent
configs to render an image correctly? Right now, the text of the
argument passed to imagejpeg is being shown instead of the image...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
| |