WebChemistry / images

Image storage for Nette Framework
36 stars 20 forks source link

How to get an image from the root of the namespace, instead of the "original" folder using localStorage? #36

Closed vylink closed 5 years ago

vylink commented 5 years ago

Hi,

I'm just trying to implement this extension to the project with huge amount of images, already saved in the individual namespaces.... Is there any way, how can I get an image form the root of individual namespaces, instead of "original" folder? I have found an option "namespaceBC" but it seems to be working on S3storage only :(

krekos commented 5 years ago

As far as i know, the 'original' folder is hardcoded. So you will have to probably move your images to original folder.

Maybe @MartkCz can give you better answer.

vylink commented 5 years ago

As far as i know, the 'original' folder is hardcoded. So you will have to probably move your images to original folder.

Maybe @MartkCz can give you better answer.

Really bad news. Can't do it as there is about 500 folders and subfolders and all images are also shared with other project.. :(

MartkCz commented 5 years ago

What is the hierarchy for example?

vylink commented 5 years ago

What is the hierarchy for example?

Hi @MartkCz , thank you for getting back to me...

The current folder structure is like following example

/www/assets/magazine/01/image.png /www/assets/magazine/02/image.png /www/assets/products/image.png /www/assets/products/image1.png /www/assets/gallery/events/event1/image.png /www/assets/gallery/people/person1/image1.png

...etc

As I mentioned before, this structure is created by 3rd party system which is also uploading all images there..so I don't need to upload those pictures there at this moment, but I'd like to use the latte macro to generate thumbnails and/or other image sizes... from existing source.

so following macro:

{img 'gallery/people/person1/image1.png', resizeExact(400, 541)}

is curently trying to locate original image in the "original" folder as follows

/www/assets/gallery/people/person1/**original**/image1.png

instead of

/www/assets/gallery/persons/person1/image1.png

I have no problem to make some workaround, but not sure how can I do it.

I've tried a code from your documentation, but it probably can't work as I don't need to save an existing original image (to get $id). Am I wrong here?

// nebo z cesty
$resource = $storage->createLocalResource($AbsolutepathToExistingImage); //image path is curently saved in the database

// pridame namespace
//$resource->setNamespace('namespace'); - it already has a namespace

// ulozime
//$result = $storage->save($resource); - it is already saved

$resource->setAlias("custom"); // this is what I want

// zobrazime url adresu
echo $storage->link($resource);
MartkCz commented 5 years ago

Now, it's impossible. In a few days I'll push some commits for greater flexibility, then after you can do this.

vylink commented 5 years ago

Now, it's impossible. In a few days I'll push some commits for greater flexibility, then after you can do this.

That would be great. Many thanks for your help! I would like to buy you a "beer". Any donations link?

MartkCz commented 5 years ago

No, I don't have. Thanks is enough for me

use WebChemistry\Images\Helpers;
use WebChemistry\Images\Resolvers\HashResolver;

class CustomHashResolver extends HashResolver {

    public function getOriginal(IResourceMeta $meta): ?string {
        return null;
    }

    public function resolve(IResourceMeta $meta): ?string {
        $aliases = $meta->getSignature();
        if (!$aliases) {
            return $this->getOriginal($meta);
        }

        return Helpers::getNameByAliases($aliases);
    }

}

dev-master has a different configuration

vylink commented 5 years ago

Thank you very much then.