I use omniauth-twitter gem. In the apply_omniauth method of my User model, I save the Twitter image path this way, removing the _normal suffix:
if omniauth['provider'] == 'twitter' self.image = omniauth['info']['image'].sub("_normal", "") end
Then I have a helper method called a portrait that takes a size argument. As Terence Eden suggests, you can simply replace the _size suffix with the file name to access the different image sizes that Twitter provides.
def portrait(size) # Twitter # mini (24x24) # normal (48x48) # bigger (73x73) # original (variable width x variable height) if self.image.include? "twimg" # determine filetype case when self.image.downcase.include?(".jpeg") filetype = ".jpeg" when self.image.downcase.include?(".jpg") filetype = ".jpg" when self.image.downcase.include?(".gif") filetype = ".gif" when self.image.downcase.include?(".png") filetype = ".png" else raise "Unable to read filetype of Twitter image for User ##{self.id}" end # return requested size if size == "original" return self.image else return self.image.gsub(filetype, "_#{size}#{filetype}") end end end
source share