Skip to content

Commit

Permalink
Develop (#10)
Browse files Browse the repository at this point in the history
* upgrade version

* readme

* update

* cleanup

* http client update

* Feature/removebg (#8)

* remove bg

* convert image issue

* remove repair image tool

* repair add

* upscale tool (#9)

* version
  • Loading branch information
maztch authored Jun 20, 2024
1 parent 3ddd914 commit 9535a46
Show file tree
Hide file tree
Showing 25 changed files with 613 additions and 1,253 deletions.
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
}
},
"require": {
"php": ">=7.1",
"ext-curl": "*"
"php": ">=7.3",
"firebase/php-jwt": "^6.0",
"guzzlehttp/guzzle": "^7.4",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.1"
"phpunit/phpunit": "^9.5",
"vimeo/psalm": "^4.21"
}
}
15 changes: 0 additions & 15 deletions phpunit.no_autoload.xml

This file was deleted.

17 changes: 9 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<phpunit bootstrap="tests/bootstrap.php" colors="true">
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" cacheResult="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Iloveimg PHP Test Suite">
<directory suffix="Test.php">tests</directory>
<exclude>./tests/TestCase.php</exclude>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
<exclude>./tests/TestCase.php</exclude>
</whitelist>
</filter>
</phpunit>
</phpunit>
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="7"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Develop and automate PDF processing tasks like Compress PDF, Merge PDF, Split PD

## Requirements

PHP 7.1 and later.
PHP 7.3 and later.

## Install

Expand Down
28 changes: 28 additions & 0 deletions samples/removebackground_advanced.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
//include the autoloader
require_once('../vendor/autoload.php');
//if manual installation has been used comment line that requires the autoload and uncomment this line:
//require_once('../init.php');


use Iloveimg\RemovebackgroundImageTask;


// you can call task class directly
// to get your key pair, please visit https://developer.iloveimg.com/user/projects
$myTask = new RemovebackgroundImageTask('project_public_id','project_secret_key');

// file var keeps info about server file id, name...
// it can be used latter to cancel file
$file = $myTask->addFile('/path/to/file/image.jpg');


// and set name for output file.
// the task will set the correct file extension for you.
$myTask->setOutputFilename('image_without_background');

// process files
$myTask->execute();

// and finally download file. If no path is set, it will be downloaded on current folder
$myTask->download('path/to/download');
22 changes: 22 additions & 0 deletions samples/removebackground_basic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
//include the autoloader
require_once('../vendor/autoload.php');
//if manual installation has been used comment line that requires the autoload and uncomment this line:
//require_once('../init.php');

use Iloveimg\RemovebackgroundImageTask;


// you can call task class directly
// to get your key pair, please visit https://developer.iloveimg.com/user/projects
$myTask = new RemovebackgroundImageTask('project_public_id','project_secret_key');

// file var keeps info about server file id, name...
// it can be used latter to cancel file
$file = $myTask->addFile('/path/to/file/image.jpg');

// process files
$myTask->execute();

// and finally download file. If no path is set, it will be downloaded on current folder
$myTask->download();
31 changes: 31 additions & 0 deletions samples/upscale_advanced.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
//include the autoloader
require_once('../vendor/autoload.php');
//if manual installation has been used comment line that requires the autoload and uncomment this line:
//require_once('../init.php');


use Iloveimg\UpscaleImageTask;


// you can call task class directly
// to get your key pair, please visit https://developer.iloveimg.com/user/projects
$myTask = new UpscaleImageTask('project_public_id','project_secret_key');

// file var keeps info about server file id, name...
// it can be used latter to cancel file
$file = $myTask->addFile('/path/to/file/image.jpg');

// set the scale
$file->setMultiplier(4);


// and set name for output file.
// the task will set the correct file extension for you.
$myTask->setOutputFilename('image_upscaled_x4');

// process files
$myTask->execute();

// and finally download file. If no path is set, it will be downloaded on current folder
$myTask->download('path/to/download');
22 changes: 22 additions & 0 deletions samples/upscale_basic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
//include the autoloader
require_once('../vendor/autoload.php');
//if manual installation has been used comment line that requires the autoload and uncomment this line:
//require_once('../init.php');

use Iloveimg\UpscaleImageTask;


// you can call task class directly
// to get your key pair, please visit https://developer.iloveimg.com/user/projects
$myTask = new UpscaleImageTask('project_public_id','project_secret_key');

// file var keeps info about server file id, name...
// it can be used latter to cancel file
$file = $myTask->addFile('/path/to/file/image.jpg');

// process files
$myTask->execute();

// and finally download file. If no path is set, it will be downloaded on current folder
$myTask->download();
18 changes: 14 additions & 4 deletions src/ConvertImageTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ConvertImageTask extends ImageTask
/**
* @var string
*/
public $to = 'jpg';
public $convert_to = 'jpg';

private $toValues = ["jpg", "png", "gif", "gif_animation"];

Expand Down Expand Up @@ -45,13 +45,23 @@ function __construct($publicKey, $secretKey, $makeStart = true)
* values: ["jpg"|"png"|"gif"]
* default: "jpg"
*/
public function setTo(string $to)
public function setConvertTo(string $convertTo)
{
$this->checkValues($to, $this->toValues);
$this->to = $to;
$this->checkValues($convertTo, $this->toValues);
$this->convert_to = $convertTo;
return $this;
}

/**
* Alias for setConvertTo
* @param string $convertTo
* @return $this
*/
public function setTo(string $convertTo)
{
return $this->setConvertTo($convertTo);
}

/**
* @param int $gif_time
* @return $this
Expand Down
57 changes: 34 additions & 23 deletions src/Exceptions/ExtendedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,70 @@
class ExtendedException extends Exception
{

/**
* @var mixed|null
*/
private $params;

/**
* @var string|null
*/
private $type;

/**
* ExtendedException constructor.
*
* @param string $message
* @param mixed $responseBody
* @param int $code
* @param Exception|null $previous
* @param $response
* @param \Throwable $previous
*/
public function __construct($message, $code = 0, Exception $previous = null, $response)
public function __construct($message, $responseBody = null, $code = 0, $previous = null)
{
if (isset($response->body->error) && $response->body->error->type) {
$this->type = $response->body->error->type;
if (!$code) {
$code = 0;
}
if ($responseBody && isset($responseBody->error) && $responseBody->error->type) {
$this->type = $responseBody->error->type;
}
if (isset($response->body->error->param)) {
$this->params = $response->body->error->param;
if ($responseBody && isset($responseBody->error) && isset($responseBody->error->param)) {
$this->params = $responseBody->error->param;
}
if ($this->params) {
if (is_array($this->params)) {
if(is_object($this->params[0])){
if (is_object($this->params[0])) {
$firstError = $this->params[0]->error; //test unlock fail
}
else{
} else {
$firstError = $this->params[0];
}
} else {
$params = json_decode(json_encode($this->params), true);

if(is_string($params)){
$firstError = $params; //download exception
}
else{
$error = array_values($params);
if (is_array($error[0])) {
$error[0] = array_values($error[0]);
$firstError = $error[0][0]; //task deleted before execute
} else {
$firstError = $error[0];
}
}
$firstError = $this->getFirstErrorString($params);
}
parent::__construct($message . ' (' . $firstError . ')', $code, $previous);
} else {
if ($responseBody && isset($responseBody->message)) {
$message .= ' (' . $responseBody->message . ')';
}
parent::__construct($message, $code, $previous);
}
}

private function getFirstErrorString($error){
if (!is_string($error)) {
return $this->getFirstErrorString(array_values($error)[0]);
}
return $error;
}

/**
* @return mixed
*/
public function getErrors()
{
if (!is_countable($this->params)) {
return [];
}
return $this->params;
}

Expand Down
7 changes: 7 additions & 0 deletions src/Exceptions/NotImplementedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Iloveimg\Exceptions;

class NotImplementedException extends \Exception {

}
4 changes: 3 additions & 1 deletion src/Exceptions/StartException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Iloveimg\Exceptions;

class StartException extends \Exception {
use Iloveimg\Exceptions\ExtendedException;

class StartException extends ExtendedException {

}
Loading

0 comments on commit 9535a46

Please sign in to comment.