mh / imagetastic
Nifty image library in my toolbox
1.0.6
2021-12-28 17:52 UTC
Requires
- php: >=5.3.3
- google/auth: ^1.4
- imagine/imagine: ^1.2
Requires (Dev)
- phpstan/phpstan: ^1.2
- phpunit/phpunit: ^8.0
- symfony/var-dumper: ^4.3
README
This is a very easy toolkit to upload images to google cloud storage including a thumbnail.
Developed by Michael Holm
Google Api: https://cloud.google.com/storage/docs/json_api/v1/
<?php
use Imagetastic\Client;
require_once(__DIR__.'/vendor/autoload.php');
// your google cloud project name
$project = 'alien-dispatch-8258';
// original picture you want to upload and create thumbnail
//$imageUrl = '/tmp/my-image-file.jpg';
$imageUrl = 'https://images.pexels.com/photos/974229/pexels-photo-974229.jpeg?auto=compress&cs=tinysrgb&h=800&w=1200';
// dimentions for the thumbnail
$dimentions = [
'height' => 300,
'width' => 400,
];
// your client key, can be downloaded from your google cloud console
$client = new Client(__DIR__.'/client.json', $project);
$r = $client->process($imageUrl, $dimentions);
var_dump($r);
The output will be something:
object(stdClass)#2 (7) {
["height"]=>
int(800)
["width"]=>
int(800)
["ratio"]=>
int(1)
["done"]=>
bool(true)
["mime"]=>
string(10) "image/jpeg"
["originalPath"]=>
string(78) "https://storage.googleapis.com/alien-dispatch-8258/original/5c59a48f95d47.jpeg"
["thumbPath"]=>
string(83) "https://storage.googleapis.com/alien-dispatch-8258/thumb_400x300/5c59a48f95d47.jpeg"
}