Skip to content

Generate Conversions Manually when Needed #1980

Answered by danFWD
danFWD asked this question in Ideas
Discussion options

You must be logged in to vote

Here is what I finally uncovered, though it still doesn't solve turning off the conversion when saving an image.

/**
 * This checks to make sure the thumb conversion exists, 
 * and if not, goes ahead and creates it. 
 */
$fileManipulator = new \Spatie\MediaLibrary\Conversions\FileManipulator;
$media = $myModel->getMedia('images');
foreach( $media as $img ) {
 if( !$img->hasGeneratedConversion('thumb') ) {
  $fileManipulator->createDerivedFiles($img);
 }
}

Tested and this generates the conversion and saves the model conversion.

Replies: 5 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@danFWD
Comment options

Comment options

You must be logged in to vote
1 reply
@danFWD
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by danFWD
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
4 participants