Closed papakay closed 7 years ago
What's the error message?
I didn't get any error message but after several retry it worked. However i observed that when i specify width and height, it doesn't generate the exact dimension. Is there a way to achieve this please?
Did you use :width
and :height
for the width/height (instead of :max_width
and :max_height
)?
Please paste the command you used.
I used this
Thumbnex.create_thumbnail("uploads/reviews/source/photos/gtbank-mobile-app-is-great-and-innovative-24160680-e8b3-4e0b-81b0-739d23dfb93d-0.3911392694825596.jpg", "uploads/test.jpg", width: 640, height: 400)
I got a dimension of 605 x 400
and the source dimension is 800 x 529
Please i'm about 3 weeks old in elixir and I would like to know whether my approach with Thumbnex is correct.
I have a form that allows user upload multiple files. And I will like to use thumbnex to generate the thumbnail after the upload. I have implemented it this but i noticed no thumbnail is generated with this approach.
Kindly see my code below.
review = Repo.get!(Review, review_id)
Enum.each Map.get(attachment_params, "attachment"), fn attachment ->
media_type =
case attachment.content_type do
"image/jpeg" -> "photos"
"image/png" -> "photos"
"image/gif" -> "photos"
"image/jpg" -> "photos"
"video/mp4" -> "videos"
_ -> nil
end
extension = Path.extname(attachment.filename)
unqiue_identifier = :rand.uniform()
media_source_filename = "#{media_type}/#{review.slug}-#{review.id}-#{unqiue_identifier}#{extension}"
upload_path = "uploads/reviews/source/#{media_source_filename}"
# Thumbnail
media_thumbnail_filename = "#{media_type}/#{review.slug}-#{review.id}-#{unqiue_identifier}.jpg"
thumbnail_path = "uploads/reviews/thumbnail/#{media_thumbnail_filename}"
File.cp(attachment.path, upload_path)
Thumbnex.create_thumbnail(upload_path, thumbnail_path, width: 600, height: 400)
end
Regarding the width/height, the resize operation preserves the aspect ratio. If you need to do additional image manipulations like stretching/cropping, you should use another library in addition to Thumbnex. Such as Mogrify.
Actually, if all you are doing is working with images and not videos, I recommend you work with Mogrify instead of using Thumbnex at all. Mogrify provides a lot more flexibility. I guess Thumbnex is more useful with animations and videos.
Thank you so much. I really appreciate this.
I was able to generate thumbnail from video but thumbnail was not generated for images.
I have Imagick 7.0.0.6 installed.
My code was this
Please what are mine doing wrong?
Thanks.