Copy platform/core/media/config/media.php
to config/media.php
and change the media sizes.
<?php
return [
...
'sizes' => [
'thumb' => '150x150',
'featured' => '560x380',
'medium' => '540x360',
],
...
];
Add to platform/themes/your-theme/functions/functions.php
or in your plugin service providers.
if (!function_exists('register_custom_image_size')) {
function register_custom_image_size()
{
config([
'media.sizes.post-small' => '200x150',
'media.sizes.featured' => '360x217', // It will overrides default size for "medium"
// You can add more sizes if you want
]);
}
}
add_action('init', 'register_custom_image_size', 1234);
How to use:
{{ get_image_url($post->image, 'post-small') }}
{{ get_object_image($post->image, 'post-small') }}
You can create your custom upload with RvMedia
facade.
Ex:
\RvMedia::handleUpload(request()->input('file'), 0, 'your-folder`);
Or
rv_media_handle_upload(request()->input('file'), 0, 'your-folder`);
To get image by size, you can use get_image_url($url, $size = null, $relative_path = false, $default = null)
.
Ex:
get_image_url($post->image, 'thumb');
If you have registered other size, you can change thumb
by your size's name.
You can fake a file upload from a path with UploadedFile
and upload it using RvMedia::handleUpload()
Ex:
$folder = \Botble\Media\Models\MediaFolder::create([
'name' => 'Example',
'slug' => 'example',
]);
$fileUpload = new \Illuminate\Http\UploadedFile(database_path('files/example.png'), 'example.png', 'image/png', null, true);
$image = \RvMedia::handleUpload($fileUpload, $folder->id);