GithubHelp home page GithubHelp logo

bluefeet / math-fitrect Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 23 KB

Resize one rect in to another while preserving aspect ratio.

Home Page: https://metacpan.org/pod/Math::FitRect

License: Other

Perl 100.00%
perl5 cpan

math-fitrect's Introduction

NAME

Math::FitRect - Resize one rect in to another while preserving aspect ratio.

SYNOPSIS

use Math::FitRect;

# This will return: {w=>40, h=>20, x=>0, y=>10}
my $rect = fit_rect( [80,40] => 40 );

# This will return: {w=>80, h=>40, x=>-19, y=>0}
my $rect = crop_rect( [80,40] => 40 );

DESCRIPTION

This module is very simple in its content but can save much time, much like other simplistic modules like Data::Pager. This module is useful for calculating what size you should resize images as for such things as thumbnails.

RECTANGLES

Rectangles may be specified in several different forms to fit your needs.

  • A simple scalar integer containg the pixel width/height of a square.
  • An array ref containing the width and height of a rectangle: [$width,$height]
  • A hash ref containg a w (width) and h (height) key: {w=>$width,h=>$height}

FUNCTIONS

fit_rect

# This will return: {w=>40, h=>20, x=>0, y=>10}
my $rect = fit_rect( [80,40] => 40 );

Takes two rectangles and fits the first one inside the second one. The rectangle that will be returned will be a hash ref with a 'w' and 'h' parameter as well as 'x' and 'y' parameters which will specify any offset.

crop_rect

# This will return: {w=>80, h=>40, x=>-19, y=>0}
my $rect = crop_rect( [80,40] => 40 );

Like the fit_rect function, crop_rect takes two rectangles as a parameter and it makes $rect1 completely fill $rect2. This can mean that the top and bottom or the left and right get chopped off (cropped). This method returns a hash ref just like fit_rect.

AUTHOR

Aran Clary Deltac [email protected]

LICENSE

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

math-fitrect's People

Contributors

bluefeet avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.