PHP code example of clear01 / images

1. Go to this page and download the library: Download clear01/images 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/ */

    

clear01 / images example snippets


composer 

class ModifiersLoader implements WebChemistry\Images\Modifiers\ILoader {
    
    public function load(WebChemistry\Images\Modifiers\ModifierContainer $modifierContainer) {
        $modifierContainer->addModifier('custom', function (ModifierParam $param, $foo) {
            // zpracovani obrazku $param->getImage()
        });
    }

}

// vytvorime zdroj pro obrazek
$resource = $storage->createUploadResource($upload);
// nebo z cesty
$resource = $storage->createLocalResource($location);

// pridame namespace
$resource->setNamespace('namespace');

// ulozime
$result = $storage->save($resource);

// zobrazime url adresu
echo $storage->link($result);

$resource->setAlias("custom");

// Kombinace více aliasů
$resource->setAliases(["custom", "custom2"]);

$id = $resource->getId(); // Ziskání id
// nebo
$id = (string) $resource;

$resource = $storage->createResource($id);

$link = $storage->link($resource);

$resource = $storage->createResource($id);
$dest = $storage->createResource("namespace/obrazek.jpg"); 

// Muzeme zmodifikovat
$dest->setAlias("custom");

$storage->copy($resource, $dest);

$resource = $storage->createResource($id);
$dest = $storage->createResource("namespace/obrazek.jpg"); 

// Muzeme zmodifikovat
$dest->setAlias("custom");

$storage->move($resource, $dest);

$resource = $storage->createResource($id);

$storage->delete($id);

$resource = $storage->createResource($id);
$resource->setAlias("custom");
$storage->save($resource);

$resource = $storage->createResource($id);
$resource->setAlias("custom");
echo $storage->link($resource);

$batch = $storage->createBatch();

$entity->image = $batch->save($resource);
$this->em->persist($entity);

$entity2->image = $batch->save($resource2);
$this->em->persist($entity2);

$batch->flush();
$this->em->flush();

$form->addImageUpload('image', 'Obrazek')
    ->setRequired()
    ->setNamespace('namespace');

$form->onSuccess[] = function ($form, array $values) use ($storage) {
    $storage->save($values['image']);
};    

$form->addImageUpload('image', 'Obrázek')
    ->setDelete('Odstranit obrázek')
    ->setNamespace('namespace');
    
$form->onSuccess[] = function ($form, array $values) use ($storage) {
	$image = $values['image'];
	if ($image->getDelete()) {
		$storage->delete($image->getDelete());
	}
	if ($image->getUpload()) {
    	$resource = $storage->save($image->getUpload());
	} else {
		$resource = $image->getDefaultValue();
	}
};

class Entity {
    
    /**
     * @ORM\Column(type="image")
     */
    protected $image;

}

$form->onSuccess[] = function ($form, $values) {
    $en = new Entity();
    $en->image = $this->storage->save($values->image);
    
    $this->em->persist($en);
    $this->em->flush();
};

$en = $this->em->getRepository(Entity::class)->find(1);
if ($en->image !== NULL) { // V pripade nullable
    $link = $this->storage->link($en->image);
}