in reply to Dealing with rectangular images

Image::ExifTool works good.

my $file = ''; my $File_Info= ''; use Image::ExifTool 'ImageInfo'; my $exifTool = new Image::ExifTool; $exifTool->Options(Binary => 1, Composite => 1, DateFormat => '%Y:%m:% +d %H:%M:%S', Unknown => 2, Verbose => 0); # Get file info my $info = $exifTool->ImageInfo($file); $File_Info .= "$_ => $$info{$_}<br>\n" foreach (sort keys %$info); print $File_Info;

There are modules that can re-size the image, but you will find that not all images will size down as well as others.

I read your post to fast. I would not suggest doing that. Just limit them and force them to make an image that fits. Because you will end up making it to hard for yourself to program. When you can do the above and have the user do the work that should have been done to the image.

Replies are listed 'Best First'.
Re^2: Dealing with rectangular images
by htmanning (Friar) on May 25, 2016 at 20:27 UTC
    Sorry, maybe I wasn't clear. I'm resizing via css so I'm not worried about that. BUT, I'd like to either use a gray background to letterbox the wide images, or display the image above the title if it is too wide. I'm using this but it's not working all the time:
    if ($picwidth / $picheight > 1.5) { $backcolor="#f5f5f5"; } else { $backcolor="#ffffff"; }
    So I divide the width by the height and if it's greater than 1.5 it should display the gray color. Some pics that the calculation equals 1.77 do not trigger the gray though. I might be doing it wrong.

      What are the values of $picwidth and $picheight that do and don't work?

      When I wrapped it in a loop to try a handful of ratios, I couldn't find any that didn't. That's why How do I post a question effectively recommends providing actual code with data that evidences the problem.

      OUTPUT:

      I'm resizing via css

      That's generally not a good idea. Images that are too big the for target display area are a waste of resources. High speed connections often aren't. And even now, a lot of people have underpowered GPUs. Also, even a small difference in size will add up, pushing up your bandwidth usage as well as your customers.

      The end result is usually much better when you tell the customers the sizes of the image areas. At very least, you avoid customer dismay when they see what your system has done to their images.