How to get resize image URL?
Please explain what you would like to get where, thanks.
{
"resize": {
"width": "1000",
"height": "null"
},
"quality" : "70%",
"upsize" : true,
"thumbnails": [
{
"name": "medium",
"scale": "50%"
},
{
"name": "small",
"scale": "25%"
},
{
"name": "cropped",
"crop": {
"width": "300",
"height": "250"
}
}
]
}
If I use this for image field how can I get all image URL? Because database have only full image.
https://the-control-group.github.io/voyager/docs/#voyager-docs-database-tools-additional-field-options
@MamunHoque, I assume you are looking for a means to access the generated thumbnails in a frontend? The file names are created by appending the thumbnail name to the image filename. I use a small function to access the thumbnail:
function thumbnail($image_path, $name)
{
$path = pathinfo($image_path);
return $path['dirname'] . DIRECTORY_SEPARATOR
. $path['filename'] . '-'
. $name . '.'
. $path['extension'];
}
@oschettler Thanks for your comment. Already I am using this way
public function getThumbAttribute(){
if(!empty($this->image)){
return url('/').'/storage/'.str_replace(".", "-medium.", $this->image);
}
else{
return 'http://placehold.it/350x200';
}
}
I moved the code to helper, in case we use it in View.
/**
* Accessing Thumbnail image helper.
* @params: $image path = assets('storage/' . image_file, 'size of image generated ')
*/
function thumbnail($image_path, $size = '')
{
$path = pathinfo($image_path);
if(!empty($size))
{
$size = '-' . $size;
}
return $path['dirname'] . '/'
. $path['filename']
. $size . '.'
. $path['extension'];
}
@uchsarath, looks nice.
For the upcoming v0.11 we have helpers, and this should maybe be added to that.
/closing since it seems resolved
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.
Most helpful comment
@MamunHoque, I assume you are looking for a means to access the generated thumbnails in a frontend? The file names are created by appending the thumbnail name to the image filename. I use a small function to access the thumbnail:
function thumbnail($image_path, $name) { $path = pathinfo($image_path); return $path['dirname'] . DIRECTORY_SEPARATOR . $path['filename'] . '-' . $name . '.' . $path['extension']; }