Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3877924
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:33:14+00:00 2026-05-19T22:33:14+00:00

I need to create images that are within a 480w x 360h pixel canvas.

  • 0

I need to create images that are within a 480w x 360h pixel “canvas”.

I did create some images from my remote url, no problem with help from stackoverflow.

However, I desire to maintain aspect ratio of the image but, have the end result be 480×360.. Therefore, a “canvas” or border then crop technique needs to be used (from what I have read) but, I cannot seem to get it going.

Here is what I have:

#!/usr/bin/perl
use Image::Resize;
use Image::Magick;
use strict;

my $new = 'path/to/image/image.jpg';
my $somewords = 'Some words';
my $imageurl='http://myimageurl.com/image.jpg';

my $p = new Image::Magick;
$p->Read("$imageurl");

 my ($origw, $origh) = $p->Get('width', 'height');
#### correct size images get processed here with just annotation ########
  if (($origw == 480) && ($origh == 360)){
  system("convert $imageurl  -fill '#FFFFFF' -font Candice -pointsize 12 -undercolor '#00000080' -gravity SouthEast -annotate +1+1 '$somewords' $new");
  }
#### process images of incorrect original size WHERE I AM STUCK #######
  if (($origw != 480) && ($origh != 360)){
system("convert $imageurl $new");
   system("convert $imageurl -resize 480x360\! -fill '#FFFFFF' -font Candice -pointsize 14 -undercolor '#00000080' -gravity SouthWest -annotate +1+1 '$somewords' $new");
  }

What I need is this:

A “canvas” size of 480 x 360.

Reduce the original image from the url to correct aspect ratio at either 480w or 360h and place it in the middle of the 480×360 canvas.

I read somewhere, that offered no examples, that I could resize original image while maintaining aspect ratio to correct height or width whichever allows the image to be largest then, divide the other param (h or w) by 2 and then make add border based on that, then crop to size. Confused the “he + double hockey sticks” out of me.

I am so lost on trying to figure this out. I am even unsure if my question here is clear and worthy of asking stackoverflow.

Seems like resizing while maintaining aspect ratio while creating a fixed output image is very difficult! Hours of searching have not helped me.

I praise the one who offers a verbose solution. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:33:15+00:00Added an answer on May 19, 2026 at 10:33 pm

    Isn’t it a bit silly to use the Image::Magick module, and then use the external convert command? You can do all of this within your Perl script using Image::Magick.

    Anyway, if you read the fine manual, you’ll find that ImageMagick will resize to the highest dimensions within 480×360 without changing the aspect ratio by using 480x360. This works both on the command-line with convert and within Image::Magick. When you add the !, you’re telling it to resize to exactly 480×360, disregarding the aspect ratio.

    This should get you started without using external commands:

    ...
    $p->Resize(geometry=>'480x360');
    $p = $p->Montage(geometry=>'480x360', background=>'black', fill=>'white',
                     stroke=>'white', pointsize=>12, title=>$somewords);
    $p->Write($new);
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a slide show of some images that can go full
I need to create a file that embeds an image as text within some
I need to create a cron job that will tar all images created within
I heard that you need to create images for both retina and non-retina. And
I need to find/create a library that can load hdr images in many formats
I'm trying to create a dependent caption display from within the Cycle call: $('#slideshow-images').cycle({
Here is my problem, I need to create a javascript function that takes 2
I need to create a fading background image that stretches to fill the browser.
How can I create a barcode image in Java? I need something that will
I just need to know hot to create a CGLayer that has an image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.