1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-02-02 11:34:20 +02:00

Update PHP URL generation example (#66)

String interpolation is a little easier to read and understand as there's no back-and-forth between string format and arguments. 

Matches JS version: https://github.com/DarthSim/imgproxy/blob/master/examples/signature.js#L27
This commit is contained in:
Adam Quaile 2018-09-06 12:36:03 +01:00 committed by Sergey Alexandrovich
parent 96249406f4
commit 09bfd44c55

View File

@ -23,8 +23,8 @@ $extension = 'png';
$url = 'http://img.example.com/pretty/image.jpg'; $url = 'http://img.example.com/pretty/image.jpg';
$encodedUrl = rtrim(strtr(base64_encode($url), '+/', '-_'), '='); $encodedUrl = rtrim(strtr(base64_encode($url), '+/', '-_'), '=');
$path = sprintf("/%s/%d/%d/%s/%d/%s.%s", $resize, $width, $height, $gravity, $enlarge, $encodedUrl, $extension); $path = "/{$resize}/{$width}/{$height}/{$gravity}/{$enlarge}/{$encodedUrl}.{$extension}";
$signature = rtrim(strtr(base64_encode(hash_hmac('sha256', $saltBin.$path, $keyBin, true)), '+/', '-_'), '='); $signature = rtrim(strtr(base64_encode(hash_hmac('sha256', $saltBin.$path, $keyBin, true)), '+/', '-_'), '=');
print(sprintf("/%s%s", $signature, $path)); print(sprintf("/%s%s", $signature, $path));