के साथ सशर्त छवि का आकार बदलना मुझे अपलोड की गई छवि के विभिन्न संस्करणों को सशर्त रूप से बनाना होगा। मुझे पता है कैरियरवेव इस सुविधा का समर्थन करता है। लेकिन मेरी आवश्यकताओं थोड़ा मुश्किल है।कैरियरवेव
प्रत्येक अपलोड की गई छवि के लिए मुझे 2 संस्करण बनाने की आवश्यकता है और शर्तों के आधार पर मूल छवि को स्केल करने की आवश्यकता है।
version :leftright, :if => :image? do
process :resize_to_fill => [667*2, 778*2] ,:if => :is_retina_resolution?
process :resize_to_fill => [667, 778] ,:if => !:is_retina_resolution?
end
version :updown, :if => :image? do
process :resize_to_fill => [1024*2, 487*2] ,:if => :is_retina_resolution?
process :resize_to_fill => [1024, 487] ,:if => !:is_retina_resolution?
end
#resize the original image
process :resize_to_fill => [1024*2, 768*2] ,:if => :is_retina_resolution?
process :resize_to_fill => [1024, 768] ,:if => !:is_retina_resolution?
def is_retina_resolution?(new_file)
image = MiniMagick::Image.open(new_file.file)
true if image[:height] >= 1536 and image[:width] >= 2048
end
जाहिर है इस काम नहीं कर रहा:
कोड नीचे आप बेहतर विचार मुझे क्या करना कोशिश कर रहा हूँ दे देंगे। Carrierwave इस त्रुटि फेंकता है:
Errno::ENOENT - No such file or directory - #<ActionDispatch::Http::UploadedFile:0xe41d508>
और मैं एक और भिन्नता की कोशिश की:
version :leftright, :if => :image? do
if :is_retina_resolution?
process :resize_to_fill => [667*2, 778*2]
else
process :resize_to_fill => [667, 778]
end
end
version :updown, :if => :image? do
if :is_retina_resolution?
process :resize_to_fill => [1024*2, 487*2]
else
process :resize_to_fill => [1024, 487]
end
end
def is_retina_resolution?(new_file)
image = MiniMagick::Image.open(new_file)
true if image[:height] >= 1536 and image[:width] >= 2048
end
यह किसी भी त्रुटि फेंक नहीं है। लेकिन यह हमेशा retina size
(1 हालत) में छवि उत्पन्न करता है
तो मैं एक और भिन्नता की कोशिश की:
version :leftright, :if => :image? && :is_retina_resolution do
process :resize_to_fill => [667*2, 778*2]
end
version :leftright, :if => :image? && !:is_retina_resolution do
process :resize_to_fill => [667, 778]
end
version :updown, :if => :image? && :is_retina_resolution do
process :resize_to_fill => [1024*2, 487*2]
end
version :updown, :if => :image? && !:is_retina_resolution do
process :resize_to_fill => [1024, 487]
end
यह does not किसी भी त्रुटि फेंक और यह भी किसी भी संस्करण नहीं बनाया।
क्या कोई मेरी मदद कर सकता है?
अद्यतन:
@DMKE द्वारा सुझाव के आधार पर, मैं इस बदलाव नहीं किया, अब यह ठीक काम करता है
version :leftright, :if => :image? do
process :resize_to_fill => [667*2, 778*2] ,:if => :is_retina_resolution?
process :resize_to_fill => [667, 778] ,:if => :is_not_retina_resolution?
end
version :updown, :if => :image? do
process :resize_to_fill => [1024*2, 487*2] ,:if => :is_retina_resolution?
process :resize_to_fill => [1024, 487] ,:if => :is_not_retina_resolution?
end
#resize the original image
process :resize_to_fill => [1024*2, 768*2] ,:if => :image_and_retina?
process :resize_to_fill => [1024, 768] ,:if => :image_and_not_retina?
process :if => :not_image?
def image_and_retina?(img)
is_img = image? img
return false unless is_img
return is_retina_resolution?(img)
end
def image_and_not_retina?(img)
is_img = image? img
return false unless is_img
return !is_retina_resolution?(img)
end
# returns true if image file
def image?(new_file)
self.file.content_type.include? 'image'
end
def not_image?(new_file)
!self.file.content_type.include? 'image'
end
def is_retina_resolution?(new_file)
image = MiniMagick::Image.open(self.file.file)
true if image[:height] >= 1536 and image[:width] >= 2048
end
def is_not_retina_resolution?(new_file)
image = MiniMagick::Image.open(self.file.file)
true if image[:height] < 1536 and image[:width] < 2048
end
धन्यवाद @ डीएमकेई, आपके सुझाव के आधार पर, मैंने कुछ बदलाव किए हैं, और यह अभी ठीक काम करता है। – RameshVel
सेवा के होने में खुशी है। – DMKE