473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to choose the correct height/width for images

Hello,
I have users that submit images to my website. By default I choose to
make the width bigger than the height because usually pictures are
taken horizontally... But in some cases people take pictures
vertically so what I'm getting at is... can I know whether an image
was taken horizontally or vertically so I can make the proper width/
height lengths so that it looks nice and not kinda weird... because if
you make the width bigger than the height of an image that is supposed
to have a bigger height than width, it looks kinda ugly.. And also is
there a way to know when I've enlarged the image too much? because if
an image submitted was small and I make it bigger, then it also
becomes kind of ugly to look at because I guess there aren't enough
pixels... thanks for your help.

Simon

Feb 1 '07 #1
8 2416
On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <ke****@gmail.comwrote:
Hello,
I have users that submit images to my website. By default I choose to
make the width bigger than the height because usually pictures are
taken horizontally... But in some cases people take pictures
vertically so what I'm getting at is... can I know whether an image
was taken horizontally or vertically so I can make the proper width/
height lengths so that it looks nice and not kinda weird... because if
you make the width bigger than the height of an image that is supposed
to have a bigger height than width, it looks kinda ugly.. And also is
there a way to know when I've enlarged the image too much? because if
an image submitted was small and I make it bigger, then it also
becomes kind of ugly to look at because I guess there aren't enough
pixels... thanks for your help.

Simon
If you are using the GD library, have a look at imagecopyresampled:

Example: "Example 2. Resampling an image proportionally"
http://php.net/imagecopyresampled

--
Curtis, http://dyersweb.com
Feb 1 '07 #2
On Feb 1, 12:10 am, Curtis <dyers...@verizon.netwrote:
On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <ken...@gmail.comwrote:
Hello,
I have users that submit images to my website. By default I choose to
make the width bigger than the height because usually pictures are
taken horizontally... But in some cases people take pictures
vertically so what I'm getting at is... can I know whether an image
was taken horizontally or vertically so I can make the proper width/
height lengths so that it looks nice and not kinda weird... because if
you make the width bigger than the height of an image that is supposed
to have a bigger height than width, it looks kinda ugly.. And also is
there a way to know when I've enlarged the image too much? because if
an image submitted was small and I make it bigger, then it also
becomes kind of ugly to look at because I guess there aren't enough
pixels... thanks for your help.
Simon

If you are using the GD library, have a look at imagecopyresampled:

Example: "Example 2. Resampling an image proportionally"http://php.net/imagecopyresampled

--
Curtis,http://dyersweb.com
Thanks, but this stuff will resize it to 200 by 200 as in the example
or 50% of the original size... But I would like to have the image
bigger horizontally if this is the images original setting... but I
don't want the images original size because someone may upload a huge
image that will take half the screen... so I need to figure out a way
to know if the original image has a bigger width or height...

Feb 1 '07 #3
Kentor wrote:
On Feb 1, 12:10 am, Curtis <dyers...@verizon.netwrote:
On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <ken...@gmail.comwrote:
Hello,
I have users that submit images to my website. By default I
choose to make the width bigger than the height because usually
pictures are taken horizontally... But in some cases people take
pictures vertically so what I'm getting at is... can I know
whether an image was taken horizontally or vertically so I can
make the proper width/ height lengths so that it looks nice and
not kinda weird... because if you make the width bigger than the
height of an image that is supposed to have a bigger height than
width, it looks kinda ugly.. And also is there a way to know when
I've enlarged the image too much? because if an image submitted
was small and I make it bigger, then it also becomes kind of ugly
to look at because I guess there aren't enough pixels... thanks
for your help.
Simon
If you are using the GD library, have a look at imagecopyresampled:

Example: "Example 2. Resampling an image
proportionally"http://php.net/imagecopyresampled

--
Curtis,http://dyersweb.com

Thanks, but this stuff will resize it to 200 by 200 as in the example
or 50% of the original size... But I would like to have the image
bigger horizontally if this is the images original setting... but I
don't want the images original size because someone may upload a huge
image that will take half the screen... so I need to figure out a way
to know if the original image has a bigger width or height...
This may sound a little bit anti-user but it would be the only surefire
way. You might want to add a note on the conditions to upload pictures.
Like "please upload photos of height x width only". I don't think it
can kill them to spruce up their images before they upload it. You can
then add conditions in your code to trap images that don't match
exactly what you're expecting and ditch it.

Personally, I'd just resize all images to a reasonable size so it
wouldn't look ugly regardless of orientation. You can do something like
google images that wraps the images with a square box so that they all
look all arranged in boxes to cancel out the random orientations.

--

Feb 1 '07 #4
On Wed, 31 Jan 2007 21:15:25 -0800, Kentor <ke****@gmail.comwrote:
On Feb 1, 12:10 am, Curtis <dyers...@verizon.netwrote:
>On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <ken...@gmail.comwrote:
Hello,
I have users that submit images to my website. By default I choose to
make the width bigger than the height because usually pictures are
taken horizontally... But in some cases people take pictures
vertically so what I'm getting at is... can I know whether an image
was taken horizontally or vertically so I can make the proper width/
height lengths so that it looks nice and not kinda weird... because if
you make the width bigger than the height of an image that is supposed
to have a bigger height than width, it looks kinda ugly.. And also is
there a way to know when I've enlarged the image too much? because if
an image submitted was small and I make it bigger, then it also
becomes kind of ugly to look at because I guess there aren't enough
pixels... thanks for your help.
Simon

If you are using the GD library, have a look at imagecopyresampled:

Example: "Example 2. Resampling an image
proportionally"http://php.net/imagecopyresampled

--
Curtis,http://dyersweb.com

Thanks, but this stuff will resize it to 200 by 200 as in the example
or 50% of the original size... But I would like to have the image
bigger horizontally if this is the images original setting... but I
don't want the images original size because someone may upload a huge
image that will take half the screen... so I need to figure out a way
to know if the original image has a bigger width or height...
That's the whole point, they specify arbitrary maximum size limits. If
someone uploaded a huge image, it would be resampled to 200x200. You can
change those size limits how you want. You can specify that the width is
bigger than the height, if you want.

--
Curtis, http://dyersweb.com
Feb 1 '07 #5
On Thu, 01 Feb 2007 05:10:10 GMT, Curtis <dy******@verizon.netwrote:
>On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <ke****@gmail.comwrote:
>Hello,
I have users that submit images to my website. By default I choose to
make the width bigger than the height because usually pictures are
taken horizontally... But in some cases people take pictures
vertically so what I'm getting at is... can I know whether an image
was taken horizontally or vertically so I can make the proper width/
height lengths so that it looks nice and not kinda weird... because if
you make the width bigger than the height of an image that is supposed
to have a bigger height than width, it looks kinda ugly.. And also is
there a way to know when I've enlarged the image too much? because if
an image submitted was small and I make it bigger, then it also
becomes kind of ugly to look at because I guess there aren't enough
pixels... thanks for your help.

Simon

If you are using the GD library, have a look at imagecopyresampled:

Example: "Example 2. Resampling an image proportionally"
http://php.net/imagecopyresampled
Also, the getimagesize function might provfe a helpful tool for some
decision-making.
Feb 1 '07 #6
You can use getimagesize() function. http://www.php.net/getimagesize

You will get the height and width of the picture.
If height width = portrait
If width height = landscape

Then you can resize the image e.g resize all height into 50 pixel
newheight = 50
newwidth = width * (50 / height)

Or e.g resize image, if potrait height = 50, if landscape width = 50

if portrait
newheight = 50
newwidth = width * (50 / height)

if landscape
newwidth = 50
newheight = height * (50/width)

------
http://www.mastervb.net
http://www.theaussiemap.com
http://www.theukmap.com
On Feb 1, 12:42 pm, "CH4:D" <bill.ga...@microsoft.comwrote:
Kentor wrote:
On Feb 1, 12:10 am, Curtis <dyers...@verizon.netwrote:
On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <ken...@gmail.comwrote:
Hello,
I have users that submit images to my website. By default I
choose to make the width bigger than the height because usually
pictures are taken horizontally... But in some cases people take
pictures vertically so what I'm getting at is... can I know
whether an image was taken horizontally or vertically so I can
make the proper width/ height lengths so that it looks nice and
not kinda weird... because if you make the width bigger than the
height of an image that is supposed to have a bigger height than
width, it looks kinda ugly.. And also is there a way to know when
I've enlarged the image too much? because if an image submitted
was small and I make it bigger, then it also becomes kind of ugly
to look at because I guess there aren't enough pixels... thanks
for your help.
Simon
If you are using the GD library, have a look at imagecopyresampled:
Example: "Example 2. Resampling an image
proportionally"http://php.net/imagecopyresampled
--
Curtis,http://dyersweb.com
Thanks, but this stuff will resize it to 200 by 200 as in the example
or 50% of the original size... But I would like to have the image
bigger horizontally if this is the images original setting... but I
don't want the images original size because someone may upload a huge
image that will take half the screen... so I need to figure out a way
to know if the original image has a bigger width or height...

This may sound a little bit anti-user but it would be the only surefire
way. You might want to add a note on the conditions to upload pictures.
Like "please upload photos of height x width only". I don't think it
can kill them to spruce up their images before they upload it. You can
then add conditions in your code to trap images that don't match
exactly what you're expecting and ditch it.

Personally, I'd just resize all images to a reasonable size so it
wouldn't look ugly regardless of orientation. You can do something like
google images that wraps the images with a square box so that they all
look all arranged in boxes to cancel out the random orientations.

--

Feb 1 '07 #7
On Feb 1, 4:41 am, "lorento" <laurente1...@yahoo.comwrote:
You can use getimagesize() function.http://www.php.net/getimagesize

You will get the height and width of the picture.
If height width = portrait
If width height = landscape

Then you can resize the image e.g resize all height into 50 pixel
newheight = 50
newwidth = width * (50 / height)

Or e.g resize image, if potrait height = 50, if landscape width = 50

if portrait
newheight = 50
newwidth = width * (50 / height)

if landscape
newwidth = 50
newheight = height * (50/width)

------http://www.mastervb.nethttp://www.theaussiemap.comhttp://www.theukmap.com
On Feb 1, 12:42 pm, "CH4:D" <bill.ga...@microsoft.comwrote:
Kentor wrote:
On Feb 1, 12:10 am, Curtis <dyers...@verizon.netwrote:
On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <ken...@gmail.comwrote:
Hello,
I have users that submit images to my website. By default I
choose to make the width bigger than the height because usually
pictures are taken horizontally... But in some cases people take
pictures vertically so what I'm getting at is... can I know
whether an image was taken horizontally or vertically so I can
make the proper width/ height lengths so that it looks nice and
not kinda weird... because if you make the width bigger than the
height of an image that is supposed to have a bigger height than
width, it looks kinda ugly.. And also is there a way to know when
I've enlarged the image too much? because if an image submitted
was small and I make it bigger, then it also becomes kind of ugly
to look at because I guess there aren't enough pixels... thanks
for your help.
Simon
If you are using the GD library, have a look at imagecopyresampled:
Example: "Example 2. Resampling an image
proportionally"http://php.net/imagecopyresampled
--
Curtis,http://dyersweb.com
Thanks, but this stuff will resize it to 200 by 200 as in the example
or 50% of the original size... But I would like to have the image
bigger horizontally if this is the images original setting... but I
don't want the images original size because someone may upload a huge
image that will take half the screen... so I need to figure out a way
to know if the original image has a bigger width or height...
This may sound a little bit anti-user but it would be the only surefire
way. You might want to add a note on the conditions to upload pictures.
Like "please upload photos of height x width only". I don't think it
can kill them to spruce up their images before they upload it. You can
then add conditions in your code to trap images that don't match
exactly what you're expecting and ditch it.
Personally, I'd just resize all images to a reasonable size so it
wouldn't look ugly regardless of orientation. You can do something like
google images that wraps the images with a square box so that they all
look all arranged in boxes to cancel out the random orientations.
--
Aha! I think http://www.php.net/getimagesize will do the job, thanks :)

Feb 1 '07 #8
VS
Sounds like you need to re-size the image based on Width / Height Ratio
between the original image and your maximum desired size. I've not done
Image re-sizing in PHP, but you might be able to devise your own based
on this bit of Perl that I used:

# CreateThumbnail(Source, Destination)
sub CreateThumbnail
{
my( $src_file, $dst_file) = @_;

my $quality = 100;
my $newwidth = 160;
my $newheight = 120;

# create a new image from original
$im = GD::Image->newFromJpeg($src_file);
($width, $height) = $im->getBounds();

# Width / Height Ratio's
$wr = $width / $newwidth;
$hr = $height / $newheight;

if ($wr $hr){
$newheight = int(($height / $wr)+0.5);
$newwidth = int(($width / $wr)+0.5);
}else{
$newheight = int(($height / $hr)+0.5);
$newwidth = int(($width / $hr)+0.5);
}

# new image for re-sized / re-sampled version
$outim = new GD::Image($newwidth, $newheight);
$outim->copyResized($im, 0, 0, 0, 0, $newwidth, $newheight,
$width, $height);
$outim->interlaced('true');

# Put a black frame around the Image
$black = $outim->colorAllocate(0,0,0);
$outim->rectangle(0,0,$newwidth-1,$newheight-1,$black);

#save the new Image...
open(DST , '>', "$dst_file") || die "could not write image: $!";
binmode DST;
print DST ($outim->jpeg($quality));
close(DST);
}

--
VS
Feb 3 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: j erickson | last post by:
with the following xsl and xml file, the display of the gif file with the <image/url> tag works. However, the gif file in the <description> tag using the name attribute "src" won't make the correct...
5
tpgames
by: tpgames | last post by:
I have my images at a different site, and wanted the game to access those images. I've changed the links in the other parts of the code, but still get a undefined error, and thought that the below...
1
by: mascouta | last post by:
I have a lot of problems with IE browser, one of them is described in this topic. in my website i have div Calculator with background image. it displayed perfectly with Firefox browser however in IE...
0
by: sannymak | last post by:
Hello All, I have some problems making the columns 100% and forcing the footer at the bottom. Please refer to the code below and let me know a solution: HTML CODE: <!DOCTYPE html PUBLIC...
6
by: Christopera | last post by:
I built a this sites http://www.ourzeal.com/walko/index.html . If you look closely at the far right column it is about 1 px higher than the other two. The source does validate. I can not however...
1
by: pravinnweb | last post by:
can anyone tell me how to set auto height to outer div that is in green box id "gray-background" it should increase relatively to inner div "smbox" here is the css and html code it should work in...
1
by: soms2m | last post by:
HELLO ALL, I want to fill the parent window height with respect to the sub window height which is loading using ajax (mootools). For example if the parent window height is normal and the loading...
19
by: Rabel | last post by:
I have a page that is using tables (please no comments about this - I understand it should be css but firefox created this template) I have a menu down the left side and the bottom is supposed to...
4
by: Christopera | last post by:
Hello, I have built a site that uses two divs, one verticle, and one horizontal as graphic style for the ite. The problem I am having is that if the browser is resized very small the divs are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
jinu1996
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...
0
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.