Skip to content
Open
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
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preset: psr2
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
},
"autoload": {
"psr-4": {
"Jens\\ImageConverter\\": "src/"
}
"ImageConverter\\": "src/"
},
"files": ["src/helper.php"]
},
"autoload-dev": {
"psr-4": {
"Jens\\ImageConverter\\Tests\\": "test/"
"ImageConverter\\Tests\\": "test/"
}
},
"require-dev": {
Expand Down
20 changes: 3 additions & 17 deletions src/ImageConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ private function saveImage($to, $image, $quality)
}


if(isset($quality) && !is_int($quality)) {
throw new \InvalidArgumentException(sprintf('The %s quality has to be an integer', $quality));
if (isset($quality) && !is_int($quality)) {
throw new \InvalidArgumentException(sprintf('The %s quality has to be an integer', $quality));
}

switch ($extension) {
Expand All @@ -100,7 +100,7 @@ private function saveImage($to, $image, $quality)
throw new \InvalidArgumentException(sprintf('The %s quality is out of range', $quality));
}
$image = imagejpeg($image, $to, $quality);
break;
break;
case 'png':
if ($quality < -1 && $quality > 9) {
throw new \InvalidArgumentException(sprintf('The %s quality is out of range', $quality));
Expand Down Expand Up @@ -169,17 +169,3 @@ private function makeDirectory($to)
return $result;
}
}

/**
* Helper function
*
* @param string $from
* @param string $to
*
* @return resource
* @throws \InvalidArgumentException
*/
function convert($from, $to, $quality = null) {
$converter = new ImageConverter();
return $converter->convert($from, $to, $quality);
}
18 changes: 18 additions & 0 deletions src/helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace ImageConverter;

/**
* Helper function
*
* @param string $from
* @param string $to
*
* @return resource
* @throws \InvalidArgumentException
*/
function convert($from, $to, $quality = null)
{
$converter = new ImageConverter();
return $converter->convert($from, $to, $quality);
}
4 changes: 2 additions & 2 deletions tests/ImageConverterTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Jens\ImageConverter\Tests;
namespace ImageConverter\Tests;

use Jens\ImageConverter\ImageConverter;
use ImageConverter\ImageConverter;
use PHPUnit\Framework\TestCase;

class ImageConverterTest extends TestCase
Expand Down