<?php
namespace Intervention\Image\Imagick;
use Intervention\Image\AbstractFont;
use Intervention\Image\Exception\RuntimeException;
use Intervention\Image\Image;
class Font extends AbstractFont
{
/**
* Draws font to given image at given position
*
* @param Image $image
* @param int $posx
* @param int $posy
* @return void
*/
public function applyToImage(Image $image, $posx = 0, $posy = 0)
{
// build draw object
$draw = new \ImagickDraw();
$draw->setStrokeAntialias(true);
$draw->setTextAntialias(true);
// set font file
if ($this->hasApplicableFontFile()) {
$draw->setFont($this->file);
} else {
throw new RuntimeException(
"Font file must be provided to apply text to image."
);
}
// parse text color
$color = new Color($this->color);
$draw->setFontSize($this->size);
$draw->setFillColor($color->getPixel());
$draw->setTextKerning($this->kerning);
// align horizontal
switch (strtolower($this->align)) {
case 'center':
$align = \Imagick::ALIGN_CENTER;
break;
case 'right':
$align = \Imagick::ALIGN_RIGHT;
break;
default:
$align = \Imagick::ALIGN_LEFT;
break;
}
$draw->setTextAlignment($align);
// align vertical
if (strtolower($this->valign) != 'bottom') {
// corrections on y-position
switch (strtolower($this->valign)) {
case 'center':
case 'middle':
// calculate box size
$dimensions = $image->getCore()->queryFontMetrics($draw, $this->text);
$posy = $posy + $dimensions['textHeight'] * 0.65 / 2;
break;
case 'top':
// calculate box size
$dimensions = $image->getCore()->queryFontMetrics($draw, $this->text, false);
$posy = $posy + $dimensions['characterHeight'];
break;
}
}
// apply to image
$image->getCore()->annotateImage($draw, $posx, $posy, $this->angle * (-1), $this->text);
}
/**
* Calculates bounding box of current font setting
*
* @return array
*/
public function getBoxSize()
{
$box = [];
// build draw object
$draw = new \ImagickDraw();
$draw->setStrokeAntialias(true);
$draw->setTextAntialias(true);
// set font file
if ($this->hasApplicableFontFile()) {
$draw->setFont($this->file);
} else {
throw new RuntimeException(
"Font file must be provided to apply text to image."
);
}
$draw->setFontSize($this->size);
$dimensions = (new \Imagick())->queryFontMetrics($draw, $this->text);
if (strlen($this->text) == 0) {
// no text -> no boxsize
$box['width'] = 0;
$box['height'] = 0;
} else {
// get boxsize
$box['width'] = intval(abs($dimensions['textWidth']));
$box['height'] = intval(abs($dimensions['textHeight']));
}
return $box;
}
}
Initiates a new payment transaction.
create-order
| Parameter | Type | Details |
|---|---|---|
| amount | decimal | Your Amount , Must be rounded at 2 precision. |
| currency | string | Currency Code, Must be in Upper Case (Alpha-3 code) |
| success_url | string | Enter your return or success URL |
| cancel_url | string (optional) | Enter your cancel or failed URL |
Request Example (guzzle)
<?php
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', $base_url.'create-order', [
'headers' => [
'Authorization' => 'Bearer '. $authorizationToken,
'accept' => 'application/json',
'content-type' => 'application/json',
],
'form_params' => [
'amount' => '$amount',
'currency' => 'currency',
'success_url' => 'success_url',
'cancel_url' => 'cancel_url',
],
]);
echo $response->getBody();
**Response: SUCCESS (200 OK)**
{
"message": {
"success": [
"Order created successfully."
]
},
"data": {
"redirect_url":"https://example.com/login/OISADFDFSDFSF",
"order_details":{
"amount" : "10",
"fixed_charge" : 2,
"percent_charge" : 1,
"total_charge" : 3,
"total_payable" : 13,
"currency" : "USD",
"expiry_time": "2024-04-25T06:48:35.984285Z",
"success_url": "http://127.0.0.1/nfcpay/user/transaction/success",
"cancel_url": "http://127.0.0.1/nfcpay/user/transaction/cancel"
}
},
"type": "success"
}
**Response: ERROR (400 FAILED)**
{
"message": {
"error": [
"Invalid token."
]
},
"data": null,
"type": "error"
}