473,405 Members | 2,185 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,405 software developers and data experts.

Fixing image size in HTML page...

43
Hello,

I would like to fix the maximum size of a picture in a list so none of the picture exceed 200 pixels in width or height.

I'm using pictures with various height and width so I can't simply fix it in the HTML code such as :

Expand|Select|Wrap|Line Numbers
  1. <img src="$photo_dir/$section.$number.$i.gif" border=2 width="200" height=200></a>
How do we read the picture dimension and then apply a simple IF fonction to fix it accordingly?

Ex.:
Expand|Select|Wrap|Line Numbers
  1. # Some Read "image size" function that will return a
  2. # value for $actual_height_size & $actual_width_size...
  3.  
  4. if ($actual_height_size > "200") {$height = "height = 200";}
  5. elsif ($actual_width_size > "200") {$width= "width =200";}
  6.  
  7. print "<img src="$photo_dir/$section.$number.$i.gif" border=2 $width $height></a>";
  8.  
So the width and height will only be set if the original picture is bigger.

Now all I need if the read function to figure out the original size.

Can anyone help?

Thanks,

yves
Jun 27 '11 #1

✓ answered by miller

There are two ways to do this mate, you can finagle the HTML so that it only shows a certain amount of the image. Or you can resize the image before including it in the html.

I would advise the latter using Image::Magick.

Expand|Select|Wrap|Line Numbers
  1. # Resize Images
  2. my $image1 = new Image::Magick;
  3. $image1->Read($fqfn);
  4. $image1->Scale(geometry => $dimensions);
  5. $image1->Set(density=>'200');
  6. $image1->Write($fqfn);
  7.  
Just read the documentation for details.

One way to do it using HTML would be to set the image as a background of a div tag with explicit size, but that's obviously a little messy, if functional.

- Miller

7 2661
miller
1,089 Expert 1GB
There are two ways to do this mate, you can finagle the HTML so that it only shows a certain amount of the image. Or you can resize the image before including it in the html.

I would advise the latter using Image::Magick.

Expand|Select|Wrap|Line Numbers
  1. # Resize Images
  2. my $image1 = new Image::Magick;
  3. $image1->Read($fqfn);
  4. $image1->Scale(geometry => $dimensions);
  5. $image1->Set(density=>'200');
  6. $image1->Write($fqfn);
  7.  
Just read the documentation for details.

One way to do it using HTML would be to set the image as a background of a div tag with explicit size, but that's obviously a little messy, if functional.

- Miller
Jun 29 '11 #2
yjulien
43
Hi Miller,

Is this rezing a temporary one or does it actually save the change?

Thanks,

Yves
Jun 29 '11 #3
miller
1,089 Expert 1GB
Resizing is a standard thing, and it will save the changes. It's up to you if the changes get saved to a new file or if they overwrite the old one.

It's a pretty standard need actually. Most websites only want to display a thumbnail of an image, so it's necessary to create a smaller size version of the original image. It sounds like that's your need as well if you want them all to be a standard size.
Jun 30 '11 #4
yjulien
43
OK thanks Miller.

I will try that and let you know.

Yves
Jun 30 '11 #5
yjulien
43
I tried your code but it does work. Do I need to instal a module ?

Thanks,

yves
Jul 1 '11 #6
yjulien
43
It looks like my server does not want to install Image::Magik module. They are server error when I tried.

I will use Image::Size and try to tweek it the HTML output to fit the needed size.

I will let you know.

Thanks Miller,

Yves
Jul 1 '11 #7
yjulien
43
Hi Miller,

Well here is what I've done. The goal is to print an image that will not exceed 200 pixels in height or width wichever is bigger. I read the image size with Image::Size and check it.

The variable $size is then used to fix the biggest size to 200 pixel. See this code:

Expand|Select|Wrap|Line Numbers
  1. # Resize Images
  2. use Image::Size;
  3. ($image_x, $image_y) = imgsize("image.gif");
  4. if ($image_x > $image_y) { $size = "width" ;}
  5. else {$size = "height" ;}
  6.  
  7. <a href="image.gif"><img src="$photo_dir/image.gif" border=2 $size="200"</a>
Not ellegant but it work!

Thanks for your help,

Yves
Jul 1 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Question | last post by:
How does one place a graphic image on the HTM page from a java script. I'd like to use the <IMG SRC> function inside the script. <img src="test.gif">
2
by: Gary \(Girish\) | last post by:
Hello: I am using SA-FileUp to enable members to upload their product images to my ISP sever. When member uploaded a new image file, the file name is replaced with the member ID and the old file...
4
by: Kenny | last post by:
I have been trying to write a script that will increase the size of and image when you mouse over it, and decrease it to original size, when you mouse out. After a couple of attempts, this is what...
7
by: Haines Brown | last post by:
I'm in the practice of specifying img width and height in my style definitions, although I usually use the actual size of the image. I'm reworking the style and it would be convenient to leave...
2
by: Jim McGivney | last post by:
On an aspx page I use the following code to display an image: //Display the graphic string imgee = this.Request.QueryString.ToString(); System.Web.UI.WebControls.Image myImage = new...
69
by: RC | last post by:
I know how to do this in JavaScript by window.open("newFile.html", "newTarget", "scrollbars=no,resizable=0,width=200,height=200"); The browser will open a new window size 200x200, not allow...
7
by: Mariusf | last post by:
I am a novice Perl programmer and need to change a perl script that I use to create web pages with thumbnail images and some text. Currently the script created a web page for each artist / category...
0
by: punitshrivastava | last post by:
Hi to All, I am Punit Shrivastava.i created one html page for this i cde like this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
5
by: teddarr | last post by:
I have this product catalog. I am to scroll through the catalog on the HTML page and use data from the XML page to display the different products with a picture of each. I have the data and the...
8
by: jayasabari | last post by:
Hi all, I am working on asp.net. Iam fixing the image height and width but it taking the orginal image size in mozilla. Working fine in IE. Can any one help me.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.