Issue
I am creating a website which allows users to post links to gif images stored externally. Unfortunately gifs are terribly expensive and luckily I have found the following website which compresses them quite radically: http://gfycat.com/
Currently my app stores the url to the linked image (as of yet it is uncompressed and without the use of gfycat)
What I would like to do is to take the url that the user posts, use it to compress the gif via gfycat.com and then store the newly generated url (pointing to the compressed image) in my database.
How would I do this?
Sorry for the long explanation btw
Solution
Just took a look at gfycat.com, seems like they do have an accessible webservice at http://gfycat.com/fetch/:url
If this is the case, and you already have the URL you can very easily grab the 'minified' version of the gif by grabbing the URL and saving the file.
So, I would probably do something like this:
- Install
carrierwave
or another image upload gem of your choice
In the case you used the above gem...
assuming Cat
is your model, and you have an uploader attached to it named gif_photo
, and also assuming the original 'gif' url is stored as original_gif_url
You can do something like the following (assuming @cat
is some instance of the cat model):
@cat.update_attribute(:remote_gif_photo_url, "http://gfycat.com/fetch/#{@cat.original_gif_url}")
as simple as that :)... to get back at the gif, you can simply call @cat.gif_photo_url
(again, assumptions for code above are using carrierwave
syntax, but can easily be done with any of its alternatives.)
Answered By - derekyau Answer Checked By - Terry (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.