PHP code example of tancky / upscale-calculator

1. Go to this page and download the library: Download tancky/upscale-calculator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tancky / upscale-calculator example snippets


use Tancky\UpscaleCalculator\Dimensions;
use Tancky\UpscaleCalculator\UpscaleCalculator;

$photo = new Dimensions(1200, 1500);

$photo->megapixels();   // 1.8
$photo->aspectRatio();  // "4:5"
$photo->orientation();  // "portrait"
(string) $photo->scale(4);            // "4800x6000"
(string) $photo->fitWithin(600, 600); // "480x600"

$calculator = new UpscaleCalculator(); // supports 2x, 4x and 6x by default

// Which factor do I need for a 4K wallpaper?
$calculator->factorFor($photo, new Dimensions(3840, 2160)); // 4.0

// Which factor do I need for an 8x10 inch print at 300 DPI?
$calculator->pixelsForPrint(8, 10);          // 2400x3000
$calculator->factorForPrint($photo, 8, 10);  // 2.0

// How large can I print the original?
$calculator->printSize($photo);
// ['width_in' => 4.0, 'height_in' => 5.0, 'width_cm' => 10.16, 'height_cm' => 12.7]

$calculator = new UpscaleCalculator([2, 3, 8]);