Voyager: {{ Voyager::image( $post->image ) }} access to the different image sizes?

Created on 5 Dec 2017  路  3Comments  路  Source: the-control-group/voyager

  • Laravel Version: 5.5.
  • Voyager Version: 1.0

This is a question

When I upload an image it lands in the db as a single hashed file name. However in the media section the file is compressed into multiple sized files which is great for a blog for example with different sized images for different places.

How do I access the different file sizes? I am using {{ Voyager::image( $post->image ) }} however, that just gives me the large size image which is not what I want for small panels etc.

Thanks

question

Most helpful comment

When you upload the image, it will create multiple sizes based on the JSON configuration settings in BREAD for that image field. The images will be named with the various presets appended to the end. For example, if you upload image1.jpg, you could get image1.jpg, image1-small.jpg, image1-medium.jpg, etc. You can then access the images the same way. Voyager::image() is just a helper to get the image. What you pass to it is the file name you want to return, which is likely stored in a model/database field. If your model is storing path/to/image1.jpg and you want the small version, you'll have to some string manipulation (i.e. str_replace('.jpg','-small.jpg', $image)).

There is one shortcut which you may be able to make use of, and it's ONLY because you're using the Post model. The Post model has a thumbnail() method which accepts the "type" (i.e. small), and appends it for you. It also ONLY works for the field named "image", but it looks like that's what you're using.

I know it's kind of ugly, but we're not putting much effort into that right now since we're going to be rewriting all image manipulation functionality in a future release.

All 3 comments

I am looking for the same thing. Any idea?

When you upload the image, it will create multiple sizes based on the JSON configuration settings in BREAD for that image field. The images will be named with the various presets appended to the end. For example, if you upload image1.jpg, you could get image1.jpg, image1-small.jpg, image1-medium.jpg, etc. You can then access the images the same way. Voyager::image() is just a helper to get the image. What you pass to it is the file name you want to return, which is likely stored in a model/database field. If your model is storing path/to/image1.jpg and you want the small version, you'll have to some string manipulation (i.e. str_replace('.jpg','-small.jpg', $image)).

There is one shortcut which you may be able to make use of, and it's ONLY because you're using the Post model. The Post model has a thumbnail() method which accepts the "type" (i.e. small), and appends it for you. It also ONLY works for the field named "image", but it looks like that's what you're using.

I know it's kind of ugly, but we're not putting much effort into that right now since we're going to be rewriting all image manipulation functionality in a future release.

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abacram picture abacram  路  3Comments

craigb88 picture craigb88  路  3Comments

ferrywae picture ferrywae  路  4Comments

IvanBohonosiuk picture IvanBohonosiuk  路  4Comments

Nagendra1421 picture Nagendra1421  路  3Comments