PHP code example of hamidatyabi / image-library
1. Go to this page and download the library: Download hamidatyabi/image-library library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hamidatyabi / image-library example snippets
try{
$ImageEncoder = new \HamidAtyabi\ImageLibrary\ImageEncoder(array("jpeg", "gif", "png"));
$result = $ImageEncoder->encode($binaryImage);
var_dump(($result));
} catch (ImageLibrary\Exceptions\LibraryNotFound $ex) {
echo ($ex->getMessage());
} catch (ImageLibrary\Exceptions\ContentTypeNotValid $ex) {
echo ($ex->getMessage());
} catch (ImageLibrary\Exceptions\FileSizeTooLarge $ex) {
echo ($ex->getMessage());
} catch (ImageLibrary\Exceptions\ExtensionNotAllow $ex) {
echo ($ex->getMessage());
}
try{
$base64EncodedImage = "/9j/4AAQSkZJRgABAQAAAQA...";
$ImageDecoder = new \HamidAtyabi\ImageLibrary\ImageDecoder($base64EncodedImage, array("jpeg", "gif", "png"));
$result = $ImageDecoder->upload("/var/www/html/uploads/");
var_dump($result);
} catch (DirectoryNotPermission $ex) {
echo ($ex->getMessage());
} catch (DirectoryNotValid $ex) {
echo ($ex->getMessage());
} catch (ImageLibrary\Exceptions\LibraryNotFound $ex) {
echo ($ex->getMessage());
} catch (ImageLibrary\Exceptions\ContentTypeNotValid $ex) {
echo ($ex->getMessage());
} catch (ImageLibrary\Exceptions\FileSizeTooLarge $ex) {
echo ($ex->getMessage());
} catch (ImageLibrary\Exceptions\ExtensionNotAllow $ex) {
echo ($ex->getMessage());
} catch (ImageLibrary\Exceptions\Base64Format $ex) {
echo ($ex->getMessage());
}