Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, json, imagick, redis, igbinary, apcu, msgpack, memcached, yaml
extensions: mbstring, intl, json, gd, imagick, redis, igbinary, apcu, msgpack, memcached, yaml
ini-values: apc.enable_cli=on, session.save_path=/tmp, extension=psr.so, extension=phalcon.so
tools: pecl

Expand Down Expand Up @@ -257,7 +257,7 @@ jobs:
needs: generate
runs-on: ${{ matrix.operating-system }}
env:
PHP_EXTENSIONS: mbstring, intl, json, yaml, apcu, imagick, igbinary, msgpack-beta, redis
PHP_EXTENSIONS: mbstring, intl, json, yaml, apcu, gd, imagick, igbinary, msgpack-beta, redis
HOMEBREW_NO_INSTALL_CLEANUP: 1
strategy:
fail-fast: false
Expand Down Expand Up @@ -405,7 +405,7 @@ jobs:
php-version: ${{ matrix.php-versions }}
ini-values: apc.enable_cli=on, session.save_path=C:\temp
tools: pecl
extensions: mbstring, intl, json, yaml, apcu, imagick, gd, redis, igbinary, sqlite3, msgpack, psr
extensions: mbstring, intl, json, yaml, apcu, gd, imagick, redis, igbinary, sqlite3, msgpack, psr
env:
PHPTS: ${{ matrix.ts }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codecoverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: mbstring, intl, json, imagick, apcu, yaml, redis, igbinary, msgpack, psr
extensions: mbstring, intl, json, gd, imagick, apcu, yaml, redis, igbinary, msgpack, psr
ini-values: apc.enable_cli=on, session.save_path=/tmp, extension=psr.so, extension=phalcon.so

- name: Common Settings
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Corrected the `Phalcon\Db\Profiler\Item` calculation for seconds [#15249](https://github.com/phalcon/cphalcon/issues/15249)
- Corrected `Phalcon\Http\Message\ServerRequestFactory` to populate with superglobals [#15286](https://github.com/phalcon/cphalcon/issues/15286)
- Corrected `Phalcon\Mvc\Model\Query\BuilderInterface::orderBy` to use `var` instead of `string` [#15415](https://github.com/phalcon/cphalcon/issues/15415)
- Corrected `Phalcon\Image\Adapter\Gd::processText` to correctly call `imagettfbbox` when a font is specified [#15188](https://github.com/phalcon/cphalcon/issues/15188)

# [5.0.0-alpha.1](https://github.com/phalcon/cphalcon/releases/tag/v5.0.0-alpha.1) (2020-03-31)

Expand Down
2 changes: 2 additions & 0 deletions docker/7.4/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ RUN apt update -y && apt install -y \

RUN curl -s https://raw.githubusercontent.com/phalcon/zephir/development/.ci/install-zephir-parser.sh | bash

RUN docker-php-ext-configure gd --with-freetype --with-jpeg=/usr/include/ --enable-gd && \

RUN docker-php-ext-install zip gmp gd intl pdo_mysql pdo_pgsql && \
docker-php-ext-enable psr redis igbinary msgpack apcu imagick yaml memcached xdebug

Expand Down
2 changes: 2 additions & 0 deletions docker/8.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ RUN cd /opt && \
RUN cd /opt && \
curl -s https://raw.githubusercontent.com/phalcon/zephir/development/.ci/install-zephir-parser.sh | bash

RUN docker-php-ext-configure gd --with-freetype --with-jpeg=/usr/include/ --enable-gd

RUN docker-php-ext-install zip gmp gd intl pdo_mysql pdo_pgsql && \
docker-php-ext-enable psr redis igbinary msgpack apcu imagick yaml memcached xdebug

Expand Down
34 changes: 22 additions & 12 deletions phalcon/Image/Adapter/Gd.zep
Original file line number Diff line number Diff line change
Expand Up @@ -591,29 +591,39 @@ class Gd extends AbstractAdapter
}
}

protected function processText(string text, int offsetX, int offsetY, int opacity, int r, int g, int b, int size, string fontfile)
{
protected function processText(
string text,
int offsetX,
int offsetY,
int opacity,
int r,
int g,
int b,
int size,
string fontfile
) {
var space, color, angle;
int s0 = 0, s1 = 0, s4 = 0, s5 = 0, width, height;
int bottomLeftX = 0, bottomLeftY = 0, topRightX = 0, topRightY = 0,
width, height;

let opacity = (int) round(abs((opacity * 127 / 100) - 127));

if fontfile {
let space = imagettfbbox(size, 0, fontfile, text);

if isset space[0] {
let s0 = (int) space[0];
let s1 = (int) space[1];
let s4 = (int) space[4];
let s5 = (int) space[5];
if false === space {
throw new Exception("Call to imagettfbbox() failed");
}

if unlikely (!s0 || !s1 || !s4 || !s5) {
throw new Exception("Call to imagettfbbox() failed");
if isset space[0] {
let bottomLeftX = (int) space[0],
bottomLeftY = (int) space[1],
topRightX = (int) space[4],
topRightY = (int) space[5];
}

let width = abs(s4 - s0) + 10;
let height = abs(s5 - s1) + 10;
let width = abs(topRightX - bottomLeftX) + 10;
let height = abs(topRightY - bottomLeftY) + 10;

if offsetX < 0 {
let offsetX = this->width - width + offsetX;
Expand Down
2 changes: 1 addition & 1 deletion tests/_data/fixtures/Traits/GdTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function getImages(): array
'png' => dataDir('assets/images/logo.png'),
];

if ($this->hasJpegSupport()) {
if (true === $this->hasJpegSupport()) {
$images['jpg'] = dataDir('assets/images/phalconphp.jpg');
}

Expand Down
212 changes: 135 additions & 77 deletions tests/unit/Image/Adapter/Gd/TextCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,116 +13,174 @@

namespace Phalcon\Test\Unit\Image\Adapter\Gd;

use Codeception\Example;
use Phalcon\Image\Adapter\Gd;
use Phalcon\Test\Fixtures\Traits\GdTrait;
use UnitTester;

use function dataDir;
use function outputDir;

class TextCest
{
use GdTrait;

/**
* Tests Phalcon\Image\Adapter\Gd :: text()
*
* @dataProvider getExamples
*
* @param UnitTester $I
* @param Example $example
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
*/
public function imageAdapterGdText(UnitTester $I)
public function imageAdapterGdText(UnitTester $I, Example $example)
{
$I->wantToTest('Image\Adapter\Gd - text()');

$this->checkJpegSupport($I);

$outputDir = 'tests/image/gd';
$image = new Gd(dataDir('assets/images/phalconphp.jpg'));
$index = $example['index'];
$outputImage = $index . 'text.jpg';
$output = outputDir($outputDir . '/' . $outputImage);

$image
->text(
$example['text'],
$example['offsetX'],
$example['offsetY'],
$example['opacity'],
$example['color'],
$example['size'],
$example['font']
)
->save($output)
;

$I->amInPath(outputDir($outputDir));
$I->seeFileFound($outputImage);

$I->assertTrue($this->checkImageHash($output, $example['hash']));
$I->safeDeleteFile($outputImage);
}

/**
* Tests Phalcon\Image\Adapter\Gd :: text()
*
* @author Phalcon Team <team@phalcon.io>
* @since 2021-04-20
* @issue 15188
*/
public function imageAdapterGdTextWithFont(UnitTester $I)
{
$I->wantToTest('Image\Adapter\Gd - text() - with font');

$this->checkJpegSupport($I);

$outputDir = 'tests/image/gd';

$params = [

$image = dataDir('assets/images/phalconphp.jpg');
$outputImage = '15188-text.jpg';
$output = outputDir($outputDir . '/' . $outputImage);
$text = 'Hello Phalcon!';
$offsetX = 50;
$offsetY = 75;
$opacity = 60;
$color = '0000FF';
$size = 24;
$font = dataDir('assets/fonts/Roboto-Light.ttf');
$hash = 'fbf9f3e3c3c18183';

$object = new Gd($image);
$object
->text($text, $offsetX, $offsetY, $opacity, $color, $size, $font)
->save($output)
;

$I->amInPath(outputDir($outputDir));
$I->seeFileFound($outputImage);

$I->assertTrue($this->checkImageHash($output, $hash));
$I->safeDeleteFile($outputImage);
}

/**
* @return array[]
*/
private function getExamples(): array
{
return [
[
'Hello Phalcon!',
false,
false,
100,
'000000',
12,
null,
'fbf9f3e3c3c18183',
'index' => 1,
'text' => 'Hello Phalcon!',
'offsetX' => false,
'offsetY' => false,
'opacity' => 100,
'color' => '000000',
'size' => 12,
'font' => null,
'hash' => 'fbf9f3e3c3c18183',
],
[
'Hello Phalcon!',
50,
false,
100,
'000000',
12,
null,
'fbf9f3e3c3c18183',
'index' => 2,
'text' => 'Hello Phalcon!',
'offsetX' => 50,
'offsetY' => false,
'opacity' => 100,
'color' => '000000',
'size' => 12,
'font' => null,
'hash' => 'fbf9f3e3c3c18183',
],
[
'Hello Phalcon!',
50,
75,
100,
'000000',
12,
null,
'fbf9f3e3c3c18183',
'index' => 3,
'text' => 'Hello Phalcon!',
'offsetX' => 50,
'offsetY' => 75,
'opacity' => 100,
'color' => '000000',
'size' => 12,
'font' => null,
'hash' => 'fbf9f3e3c3c18183',
],
[
'Hello Phalcon!',
50,
75,
60,
'000000',
12,
null,
'fbf9f3e3c3c18183',
'index' => 4,
'text' => 'Hello Phalcon!',
'offsetX' => 50,
'offsetY' => 75,
'opacity' => 60,
'color' => '000000',
'size' => 12,
'font' => null,
'hash' => 'fbf9f3e3c3c18183',
],
[
'Hello Phalcon!',
50,
75,
60,
'00FF00',
12,
null,
'fbf9f3e3c3c18183',
'index' => 5,
'text' => 'Hello Phalcon!',
'offsetX' => 50,
'offsetY' => 75,
'opacity' => 60,
'color' => '00FF00',
'size' => 12,
'font' => null,
'hash' => 'fbf9f3e3c3c18183',
],
[
'Hello Phalcon!',
50,
75,
60,
'0000FF',
24,
null,
'fbf9f3e3c3c18183',
'index' => 6,
'text' => 'Hello Phalcon!',
'offsetX' => 50,
'offsetY' => 75,
'opacity' => 60,
'color' => '0000FF',
'size' => 24,
'font' => null,
'hash' => 'fbf9f3e3c3c18183',
],
];

$i = 0;

foreach ($params as [$text, $offsetX, $offsetY, $opacity, $color, $size, $font, $hash]) {
$image = new Gd(
dataDir('assets/images/phalconphp.jpg')
);

$outputImage = $i++ . 'text.jpg';
$output = outputDir($outputDir . '/' . $outputImage);

$image->text($text, $offsetX, $offsetY, $opacity, $color, $size, $font)
->save($output)
;

$I->amInPath(
outputDir($outputDir)
);

$I->seeFileFound($outputImage);

$I->assertTrue(
$this->checkImageHash($output, $hash)
);

$I->safeDeleteFile($outputImage);
}
}
}