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 : - <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.: -
# Some Read "image size" function that will return a
-
# value for $actual_height_size & $actual_width_size...
-
-
if ($actual_height_size > "200") {$height = "height = 200";}
-
elsif ($actual_width_size > "200") {$width= "width =200";}
-
-
print "<img src="$photo_dir/$section.$number.$i.gif" border=2 $width $height></a>";
-
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
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. -
# Resize Images
-
my $image1 = new Image::Magick;
-
$image1->Read($fqfn);
-
$image1->Scale(geometry => $dimensions);
-
$image1->Set(density=>'200');
-
$image1->Write($fqfn);
-
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
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. -
# Resize Images
-
my $image1 = new Image::Magick;
-
$image1->Read($fqfn);
-
$image1->Scale(geometry => $dimensions);
-
$image1->Set(density=>'200');
-
$image1->Write($fqfn);
-
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
Hi Miller,
Is this rezing a temporary one or does it actually save the change?
Thanks,
Yves
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.
OK thanks Miller.
I will try that and let you know.
Yves
I tried your code but it does work. Do I need to instal a module ?
Thanks,
yves
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
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: - # Resize Images
-
use Image::Size;
-
($image_x, $image_y) = imgsize("image.gif");
-
if ($image_x > $image_y) { $size = "width" ;}
-
else {$size = "height" ;}
-
-
<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
Sign in to post your reply or Sign up for a free account.
Similar topics
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">
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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"...
|
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...
|
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.
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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: 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,...
|
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: 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: 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,...
| |