uploadcare/uploadcare-php

How to get dimensions of an image of a transformed URL?

yahya-uddin opened this issue · 2 comments

Question

I have the following transformed URL given by the uploader like so:
https://ucarecdn.com/8ee8182c-8927-4cdc-8338-d66e4dabf119/-/crop/270x152/0,59/-/resize/1600x900/

I am able to get the original dimensions using the following code:

$uuidRegexp = FileApi::UUID_REGEX;
preg_match(
    "/https:\/\/ucarecdn.com\/($uuidRegexp)/",
    $url,
    $matches
);

$uuid = $matches[1];
$file = $api->file()->fileInfo($uuid);

However, I would also like to get the dimensions of the transformed URL, caused by "-/crop/270x152/0,59/-/resize/1600x900/".
Is there anyway to do this?

This is our plan to next version @yahya-uddin

@yahya-uddin you can see dimensions in response headers x-image-width and x-image-height. You also can use the special "json" operation: just add -/json/ to your URL and you will have something like that in response:

{
	"id": "/63dc9667-0311-4a27-9ad7-84317971ec26/-/crop/270x152/0,59/-/resize/1600x900/",
	"original": {
		"id": "63dc9667-0311-4a27-9ad7-84317971ec26",
		"width": 4032,
		"height": 3024,
		"format": "JPEG",
		"color_mode": "RGB",
		"orientation": 1,
		"dpi": [
			72,
			72
		],
		"datetime_original": "2017-12-11T23:12:46",
		"sequence": false
	},
	"width": 1600,
	"height": 900,
	"hash": "da3667f6f8644144"
}