Browse Source

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
Adam Quaile 6 năm trước cách đây
mục cha
commit
09bfd44c55
1 tập tin đã thay đổi với 2 bổ sung2 xóa
  1. 2 2
      examples/signature.php

+ 2 - 2
examples/signature.php

@@ -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));