Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
k-holy committed Dec 2, 2015
2 parents 1ef8302 + 49c541d commit b2a22af
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 79 deletions.
70 changes: 0 additions & 70 deletions example/index.php

This file was deleted.

8 changes: 6 additions & 2 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,9 @@ private function initializeByPath($path)
$this->path = $path;
$this->width = $imageInfo[0];
$this->height = $imageInfo[1];
$this->type = $imageInfo[2];
if ($this->type === null) {
$this->type = $imageInfo[2];
}
$resource = imagecreatefromstring($this->data);
if (!$this->validResource($resource)) {
throw new \InvalidArgumentException('Could not create GD resource.');
Expand All @@ -652,7 +654,9 @@ private function initializeByData($data)
$this->data = $data;
$this->width = $imageInfo[0];
$this->height = $imageInfo[1];
$this->type = $imageInfo[2];
if ($this->type === null) {
$this->type = $imageInfo[2];
}
$resource = imagecreatefromstring($this->data);
if (!$this->validResource($resource)) {
throw new \InvalidArgumentException('Could not create GD resource.');
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
68 changes: 61 additions & 7 deletions tests/Volcanus/Thumbnail/Test/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->srcDirectory = realpath(__DIR__ . '/../../../../images');
$this->srcDirectory = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'src';
$this->dstDirectory = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'tmp';
}

Expand All @@ -46,6 +46,21 @@ public function testInitializeByPath()
$this->assertEquals(600, $image->getHeight());
}

public function testInitializeByPathWithType()
{
$path = $this->srcDirectory . DIRECTORY_SEPARATOR . '800-600.png';
$data = file_get_contents($path);
$image = new Image(array(
'path' => $path,
'type' => IMAGETYPE_JPEG,
));
$this->assertEquals($path, $image->getPath());
$this->assertEquals($data, $image->getData());
$this->assertEquals(IMAGETYPE_JPEG, $image->getType());
$this->assertEquals(800, $image->getWidth());
$this->assertEquals(600, $image->getHeight());
}

public function testInitializeByPathSplFileInfo()
{
$path = new \SplFileInfo($this->srcDirectory . DIRECTORY_SEPARATOR . '800-600.png');
Expand All @@ -63,6 +78,24 @@ public function testInitializeByPathSplFileInfo()
$this->assertEquals(600, $image->getHeight());
}

public function testInitializeByPathSplFileInfoWithType()
{
$path = new \SplFileInfo($this->srcDirectory . DIRECTORY_SEPARATOR . '800-600.png');
ob_start();
$path->openFile('r')->fpassthru();
$data = ob_get_contents();
ob_end_clean();
$image = new Image(array(
'path' => $path,
'type' => IMAGETYPE_JPEG,
));
$this->assertEquals($path, $image->getPath());
$this->assertEquals($data, $image->getData());
$this->assertEquals(IMAGETYPE_JPEG, $image->getType());
$this->assertEquals(800, $image->getWidth());
$this->assertEquals(600, $image->getHeight());
}

public function testInitializeByData()
{
$data = file_get_contents($this->srcDirectory . DIRECTORY_SEPARATOR . '800-600.png');
Expand All @@ -71,6 +104,21 @@ public function testInitializeByData()
));
$this->assertNull($image->getPath());
$this->assertEquals($data, $image->getData());
$this->assertEquals(IMAGETYPE_PNG, $image->getType());
$this->assertEquals(800, $image->getWidth());
$this->assertEquals(600, $image->getHeight());
}

public function testInitializeByDataWithType()
{
$data = file_get_contents($this->srcDirectory . DIRECTORY_SEPARATOR . '800-600.png');
$image = new Image(array(
'data' => $data,
'type' => IMAGETYPE_JPEG,
));
$this->assertNull($image->getPath());
$this->assertEquals($data, $image->getData());
$this->assertEquals(IMAGETYPE_JPEG, $image->getType());
$this->assertEquals(800, $image->getWidth());
$this->assertEquals(600, $image->getHeight());
}
Expand Down Expand Up @@ -216,8 +264,9 @@ public function testConvertPngToJpeg()
$dstPath = $this->dstDirectory . DIRECTORY_SEPARATOR . sprintf('800-600.%s.jpg', __FUNCTION__);
$srcImage = new Image(array(
'path' => $this->srcDirectory . DIRECTORY_SEPARATOR . '800-600.png',
'type' => IMAGETYPE_JPEG,
));
$srcImage->output($dstPath, IMAGETYPE_JPEG);
$srcImage->output($dstPath);
$imageInfo = getimagesize($dstPath);
$this->assertEquals(IMAGETYPE_JPEG, $imageInfo[2]);
}
Expand All @@ -227,8 +276,9 @@ public function testConvertPngToGif()
$dstPath = $this->dstDirectory . DIRECTORY_SEPARATOR . sprintf('800-600.%s.gif', __FUNCTION__);
$srcImage = new Image(array(
'path' => $this->srcDirectory . DIRECTORY_SEPARATOR . '800-600.png',
'type' => IMAGETYPE_GIF,
));
$srcImage->output($dstPath, IMAGETYPE_GIF);
$srcImage->output($dstPath);
$imageInfo = getimagesize($dstPath);
$this->assertEquals(IMAGETYPE_GIF, $imageInfo[2]);
}
Expand All @@ -238,8 +288,9 @@ public function testConvertJpegToPng()
$dstPath = $this->dstDirectory . DIRECTORY_SEPARATOR . sprintf('800-600.%s.png', __FUNCTION__);
$srcImage = new Image(array(
'path' => $this->srcDirectory . DIRECTORY_SEPARATOR . '800-600.jpg',
'type' => IMAGETYPE_PNG,
));
$srcImage->output($dstPath, IMAGETYPE_PNG);
$srcImage->output($dstPath);
$imageInfo = getimagesize($dstPath);
$this->assertEquals(IMAGETYPE_PNG, $imageInfo[2]);
}
Expand All @@ -249,8 +300,9 @@ public function testConvertJpegToGif()
$dstPath = $this->dstDirectory . DIRECTORY_SEPARATOR . sprintf('800-600.%s.gif', __FUNCTION__);
$srcImage = new Image(array(
'path' => $this->srcDirectory . DIRECTORY_SEPARATOR . '800-600.jpg',
'type' => IMAGETYPE_GIF,
));
$srcImage->output($dstPath, IMAGETYPE_GIF);
$srcImage->output($dstPath);
$imageInfo = getimagesize($dstPath);
$this->assertEquals(IMAGETYPE_GIF, $imageInfo[2]);
}
Expand All @@ -260,8 +312,9 @@ public function testConvertGifToJpeg()
$dstPath = $this->dstDirectory . DIRECTORY_SEPARATOR . sprintf('800-600.%s.jpg', __FUNCTION__);
$srcImage = new Image(array(
'path' => $this->srcDirectory . DIRECTORY_SEPARATOR . '800-600.gif',
'type' => IMAGETYPE_JPEG,
));
$srcImage->output($dstPath, IMAGETYPE_JPEG);
$srcImage->output($dstPath);
$imageInfo = getimagesize($dstPath);
$this->assertEquals(IMAGETYPE_JPEG, $imageInfo[2]);
}
Expand All @@ -271,8 +324,9 @@ public function testConvertGifToPng()
$dstPath = $this->dstDirectory . DIRECTORY_SEPARATOR . sprintf('800-600.%s.png', __FUNCTION__);
$srcImage = new Image(array(
'path' => $this->srcDirectory . DIRECTORY_SEPARATOR . '800-600.gif',
'type' => IMAGETYPE_PNG,
));
$srcImage->output($dstPath, IMAGETYPE_PNG);
$srcImage->output($dstPath);
$imageInfo = getimagesize($dstPath);
$this->assertEquals(IMAGETYPE_PNG, $imageInfo[2]);
}
Expand Down

0 comments on commit b2a22af

Please sign in to comment.