Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
HasImages adds images and galleries to your ActiveRecord models. It comes with the follwing methods:
model.images # returns a list of all images
model.avatar # returns the image with the avatar flag e.g. the first image
model.galleries? # does this model have a gallery?
model.galleries # returns a list of the models image galleries
gallery.images # returns all images in a gallery
image.set_avatar # sets the avatar flag on this image
This gem requires thoughtbot's paperclip, this gem will be installed automatically.
add the following to your config/enviroment.rb
config.gem "has_images"
./script/generate has_images
rake db:migrate
class User < ActiveRecord::Base
has_images
end
you can also customize the image-storage with paperclip options
class User < ActiveRecord::Base
has_images :styles => {
:thumb => ["150x100", :jpg],
:mini => ["75x50", :jpg],
:medium => ["300x200", :jpg],
:large => ["640x480", :jpg],
:huge => ["800x600", :jpg],
:square => ["200x200", :jpg] },
:path => ":rails_root/public/images/:attachment/:id_partition/:id_:style.:extension",
:url => "/images/:attachment/:id_partition/:id_:style.:extension"
end
in your view (uses formtastic)
-semantic_form_for @image, :html => { :multipart => true } do |f|
-f.inputs do
=f.input :gallery_id, :as => :select, :collection => parent.galleries.all(:order=>'name')
=f.input :gallery_name
=f.input :name
=f.input :text
=f.file_field :file, :input_html => { :size => 22 }
=f.buttons
in your controller:
class ImagesController
def new
@image = User.first.images.new
end
def create
.....
@image = User.first.images.create(params[:image])
.....
end
end
has_images supports an easy method to create images from URLs:
user = User.first
image = user.create_image_by_url("http://image.url/file.png")
Of course you can also create the image manually with more arguments
user = User.first
user.images.create(:file_url => "http://image.url/file.png", :name => "my image")
class User < ActiveRecord::Base
has_images :styles => {
:thumb => ["150x100", :jpg]
},
:path => ":rails_root/public/images/:attachment/:id_partition/:id_:style.:extension",
:url => "/images/:attachment/:id_partition/:id_:style.:extension",
:counter_cache => "images_count"
end
This enables the counter_cache for the user-model. CounterCache is saved in the field "images_count"
has_images also supports image galleries to group images
gallery = user.galleries.create(:name => "gallery name")
gallery.images.create(params[:image])
gallery.create_image_by_url("http://image.url/file.png")
You can also create image galleries on the fly with the attr_accessor gallery_name:
user = User.find(1)
image = user.images.create(:name => 'my cool image', :file_url => "http://image.url/image.jpg", :gallery_name => "my images")
Sometimes you also have to group your images by specific image types. For example you could use the types "logo", "screenshot" and "banner"
You can easily create ImageType like this:
Digineo::ImageType.create(:name => 'logo')
Digineo::ImageType.create(:name => 'screenshot')
Digineo::ImageType.create(:name => 'banner')
another possibility is to create image types on the fly like this
user = User.first
user.images.create(:name => 'my cool image', :file_url => "http://image.url/image.jpg", :image_type_name => 'logo')
in this case the ImageType "logo" will eiter be created or the id of an existing ImageType will be set
user = User.first
logos = user.images.image_type('logo')
invalid image types will raise an Digineo::ImageType::Exception
user = User.first
invalid = user.images.image_type('invalid image type')
=> Digineo::ImageType::Exception: Could not find ImageType with name invalid image type
has_images also supports image cropping
user = User.first
user.avatar.crop(:style => :original, :x1 => 1, :y1 => 1, :x2 => 100, :y2 => 100, :width => 100, :height => 100)
this will use the original-image and crops the area between 1x1 and 100x100 and regenerates all thumbnails afterwards
Copyright (c) 2010 Dennis Meise Digineo GmbH , released under the MIT license
FAQs
Unknown package
We found that has_images demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.