legiaifenix / arcadia by legiaifenix

Arcadia aims to provide a quick image parsing and uploading solution using laravel tooling. The idea is to just pass the file and have everything done for you
43
0
2
Package Data
Maintainer Username: legiaifenix
Maintainer Contact: legiaifenix@gmail.com (Legiai Fenix)
Package Create Date: 2017-02-03
Package Last Update: 2020-10-28
Language: PHP
License: MIT
Last Refreshed: 2024-05-07 15:05:39
Package Statistics
Total Downloads: 43
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Arcadia

Created By: Legiai Fenix Started At: 03/02/2017

Description:

Arcadia aims to provide a quick image parsing and uploading solution. The idea is to just pass the file and have everything done for you Please note that this package is under development and aims to help the production of developers so they can focus on other aspects of their projects.

Introduction to the package name: Arcadia was a greek land that became an imaginary country with time by the hand of many poets and artists. Within Arcadia, reigns happiness, simplicity and beauty. Since the package aims to provide a simple and clean way to manage the images that are sent by clients we though the name was just on spot. We aim to provide simple and clean solutions to real problems, leaving the developers happy.

##Functionalities

    |       Functionality         |    Function Name   |       Variables       |    Returns       |
    |-----------------------------|--------------------|-----------------------|------------------|
    |  Add Images                 |    uploadImage()   |  file_name, path      | false, filename  |
    |  List Images From Folder    |    listImages()    |  folder, amount, type | array            |
    |  Deletes Images From Folder |    deleteImage()   |  image with path      | boolean          |

##Usage

First we are going to need to create a factory that will manage all our functionalities.

This factory will require you to already provide the path you wish to store your images. If not provided it will use default as public and uploads. It is inspired in the Laravel folder structure where images are sent to the path /public/

If you provide the first arguments it will keep your folder structure to store the images:

   new ArcadiaFactory('web', 'uploads');

We can also specify a limit for the images upload at the end of the variables when creating the factory object. If nothing is specified it will limit to 2MB. In this example we are allowing 50MB. Of course, always make sure your php.ini accepts your variables.

  new ArcadiaFactory('public', 'uploads', 50000);

##It all starts from somewhere

Arcadia will instanciate a model through the factory initiation. You can access such object to ask it to do the functionalities you desire, by just asking for it via factory:

    $arcadiaF->getFactory();

##Uploading an image

We can start uploading an image by passing the field parameter through our factory:

    $arcadiaF = new ArcadiaFactory('public', 'uploads');
    $arcadiaF->getFactory()->uploadImage('img');

If no path is specified when uploading it will follow a WP structure inside the target folder specified when constructing the factory. But if you wish to specify a different folder you can pass a path into it. What it will do is check the root folder and check if the specified new one exists (will create if don't). Then uploads the file.

    $arcadiaF = new ArcadiaFactory('public', 'uploads');
    $arcadiaF->getFactory()->uploadImage('img', 'tmp');

Where img field exists as html file input:

    <input type="file" name="img">

##List images from a specific folder

Because we wanted to allow you to list any folder you wish, you are able to specify the amount you wish to load (future development will allow image pagination), from where you wish to list and what type.

Example of listing all svgs from uploads/2017/02:

    $factory->getFactory()->listImages('/uploads/2017/02/', -1, 'svg');

Example of listing the first 5 jpgs from uploads/2017/02:

    $factory->getFactory()->listImages('uploads/2017/02/', 5, 'jpg');

Example of returned array:

    array(3) {
      [0]=>
      string(80) "/var/www/frame-tester/public/uploads/2017/02/04-02-2017_03-28-42_test_original.jpg"
      [1]=>
      string(80) "/var/www/frame-tester/public/uploads/2017/02/04-02-2017_03-46-13_test_original.jpg"
      [2]=>
      string(80) "/var/www/frame-tester/public/uploads/2017/02/04-02-2017_03-46-18_test_original.jpg"
    }

##Deleting images from a folder

Just pass the path for the image with the image name, the program will delete it from there if it sees it exists. It only allows you to delete images from a folder as it checks if it is an image. Acceptable types are:

    svg
    png
    jpeg
    jpg
    gif

You can also delete all images from a folder by using the list function in a for loop with the delete:

    $list = $factory->getFactory()->listImages('/uploads/2017/02');
    foreach ($list as $item) {
    	$factory->getFactory()->deleteImage($item);
    }

Or even just delete .gifs from a folder:

    $list = $factory->getFactory()->listImages('/uploads/2017/02', 'gif');
    foreach ($list as $item) {
    	$factory->getFactory()->deleteImage($item);
    }