Skip to content

Commit

Permalink
Merge pull request #15989 from niden/T15977-gd-webm
Browse files Browse the repository at this point in the history
T15977 gd webm
  • Loading branch information
niden authored Jun 10, 2022
2 parents 7087e5e + 77ff9c6 commit 02f0f5f
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 34 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# [5.0.0rc3](https://github.com/phalcon/cphalcon/releases/tag/v5.0.0RC2) (xxxx-xx-xx)

## Added
- Added support for `webp` images for `Phalcon\Image\Adapter\Gd` [#15977](https://github.com/phalcon/cphalcon/issues/15977)

# [5.0.0rc2](https://github.com/phalcon/cphalcon/releases/tag/v5.0.0RC2) (2022-06-09)

## Changed
Expand Down
11 changes: 9 additions & 2 deletions docker/7.4/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ RUN apt update -y && \
libpng-dev \
libpq-dev \
libyaml-dev \
libwebp-dev \
libxpm-dev \
libzip-dev \
locales \
nano \
sudo \
wget \
zip
zip \
zlib1g

# PECL Packages
RUN pecl install -o -f redis && \
Expand All @@ -59,7 +62,11 @@ RUN sed -i -e 's/# de_DE.UTF-8 UTF-8/de_DE.UTF-8 UTF-8/' /etc/locale.gen && \
update-locale LANG=en_US.UTF-8

# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg=/usr/include/ --enable-gd
RUN docker-php-ext-configure gd --with-freetype \
--with-jpeg=/usr/include/ \
--with-xpm \
--with-webp \
--enable-gd

RUN docker-php-ext-install \
gd \
Expand Down
8 changes: 7 additions & 1 deletion docker/8.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ RUN apt update -y && \
libpng-dev \
libpq-dev \
libyaml-dev \
libwebp-dev \
libxpm-dev \
libzip-dev \
locales \
nano \
Expand Down Expand Up @@ -59,7 +61,11 @@ RUN sed -i -e 's/# de_DE.UTF-8 UTF-8/de_DE.UTF-8 UTF-8/' /etc/locale.gen && \
update-locale LANG=en_US.UTF-8

# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg=/usr/include/ --enable-gd
RUN docker-php-ext-configure gd --with-freetype \
--with-jpeg=/usr/include/ \
--with-xpm \
--with-webp \
--enable-gd

RUN docker-php-ext-install \
gd \
Expand Down
8 changes: 7 additions & 1 deletion docker/8.1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ RUN apt update -y && \
libpng-dev \
libpq-dev \
libyaml-dev \
libwebp-dev \
libxpm-dev \
libzip-dev \
locales \
nano \
Expand Down Expand Up @@ -59,7 +61,11 @@ RUN sed -i -e 's/# de_DE.UTF-8 UTF-8/de_DE.UTF-8 UTF-8/' /etc/locale.gen && \
update-locale LANG=en_US.UTF-8

# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg=/usr/include/ --enable-gd
RUN docker-php-ext-configure gd --with-freetype \
--with-jpeg=/usr/include/ \
--with-xpm \
--with-webp \
--enable-gd

RUN docker-php-ext-install \
gd \
Expand Down
21 changes: 13 additions & 8 deletions phalcon/Image/Adapter/Gd.zep
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,35 @@ class Gd extends AbstractAdapter
let imageinfo = getimagesize(this->file);

if imageinfo {
let this->width = imageinfo[0];
let this->width = imageinfo[0];
let this->height = imageinfo[1];
let this->type = imageinfo[2];
let this->mime = imageinfo["mime"];
let this->type = imageinfo[2];
let this->mime = imageinfo["mime"];
}

switch this->type {
case 1:
case IMAGETYPE_GIF:
let this->image = imagecreatefromgif(this->file);
break;

case 2:
case IMAGETYPE_JPEG:
case IMAGETYPE_JPEG2000:
let this->image = imagecreatefromjpeg(this->file);
break;

case 3:
case IMAGETYPE_PNG:
let this->image = imagecreatefrompng(this->file);
break;

case 15:
case IMAGETYPE_WEBP:
let this->image = imagecreatefromwebp(this->file);
break;

case IMAGETYPE_WBMP:
let this->image = imagecreatefromwbmp(this->file);
break;

case 16:
case IMAGETYPE_XBM:
let this->image = imagecreatefromxbm(this->file);
break;

Expand Down
Binary file added tests/_data/assets/images/house.webp
Binary file not shown.
61 changes: 39 additions & 22 deletions tests/unit/Image/Adapter/Gd/GetMimeCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,66 @@

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

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

use function dataDir;

class GetMimeCest
{
use GdTrait;

/**
* Tests Phalcon\Image\Adapter\Gd :: getMime()
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
* @dataProvider getExamples
*
* @param UnitTester $I
* @param Example $example
*
* @return void
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
*/
public function imageAdapterGdGetMimeImageJpeg(UnitTester $I)
public function imageAdapterGdGetMime(UnitTester $I, Example $example)
{
$I->wantToTest('Image\Adapter\Gd - getMime() - image/jpg');
$I->wantToTest('Image\Adapter\Gd - getMime() - ' . $example['label']);

$this->checkJpegSupport($I);

$gd = new Gd(dataDir('assets/images/phalconphp.jpg'));
$source = $example['source'];
$expected = $example['expected'];

$gd = new Gd($source);

$I->assertSame(
'image/jpeg',
$gd->getMime()
);
$actual = $gd->getMime();
$I->assertSame($expected, $actual);
}

/**
* Tests Phalcon\Image\Adapter\Gd :: getMime()
*
* @author Phalcon Team <team@phalcon.io>
* @since 2018-11-13
* @return array[]
*/
public function imageAdapterGdGetMimeImagePng(UnitTester $I)
private function getExamples(): array
{
$I->wantToTest('Image\Adapter\Gd - getMime() - image/png');

$gd = new Gd(dataDir('assets/images/logo.png'));

$I->assertSame(
'image/png',
$gd->getMime()
);
return [
[
'label' => 'JPEG',
'source' => dataDir('assets/images/phalconphp.jpg'),
'expected' => 'image/jpeg',
],
[
'label' => 'PNG',
'source' => dataDir('assets/images/logo.png'),
'expected' => 'image/png',
],
[
'label' => 'WEBP',
'source' => dataDir('assets/images/house.webp'),
'expected' => 'image/webp',
],
];
}
}

0 comments on commit 02f0f5f

Please sign in to comment.