2011-10-12 16 views
10

मुझे इस छवि से सफेद पृष्ठभूमि को हटाने और पृष्ठभूमि को पारदर्शी बनाने की आवश्यकता है। तो यह एक पीएनजी के रूप में निर्यात पारदर्शी पृष्ठभूमि पर सिर्फ एक काला टिक है।RMagick छवि से सफेद पृष्ठभूमि को हटा दें और इसे पारदर्शी बनाएं

उदा। मुड़ें

enter image description here

में

enter image description here

कोई भी विचार?

उत्तर

9

convert image.png -matte -fill none -fuzz 1% -opaque white result.png

पारदर्शिता के साथ सफेद कुछ भी बदलता है। फ़ज़ विकल्प में कुछ भी शामिल है जो लगभग-सफेद है।

+2

आप इसे rmagick में कैसे परिवर्तित करते हैं? – hadees

+0

@ hadees यह एक अच्छी शुरुआत की तरह दिखता है: [ImageMagick को समझना और रूबी RMagick में अनुवाद करना] (http://stackoverflow.com/questions/4132787/understanding-imagemagicks-convert-and-translating-to-ruby-rmagick) –

1
v6.8.4-प्रश्न 16 के साथ

नीचे आदेश का उपयोग: में

convert nike.png -matte -fill none -fuzz 1% -opaque white nikeOutput.png 

परिणाम:

convert nike.jpg -transparent white NikeProd.png 

enter image description here

:

enter image description here

यहाँ आदेश मैं का उपयोग करें

enter image description here

2

मैं जानता हूँ कि मैं बहुत पार्टी के लिए देर से कर रहा हूँ, लेकिन जब से यह सवाल पहले पोस्ट किया गया था बहुत कुछ बदल गया है, तो आप निम्न तरीके से यह आज कम से कम rmagick

की 2.15.4 संस्करण मान लिया जाये कि का उपयोग कर सकते है आप छवि कहीं सुलभ है:

image = Magick::Image.new(path_to_file) 
image.background_color = 'none' 

आप भी छवि ट्रिम करने के लिए चाहते हैं तो यह केवल यह सीमाओं के रूप में के रूप में बड़ा है, बस का उपयोग .trim!

image.trim! 

संपादित करें:

बाहर कर देता है इसके बाद के संस्करण समाधान वास्तव में सभी उपयोग के मामलों के लिए काम नहीं करता। एक और सामान्य समाधान यह है:

# the image needs to be in 'PNG' format 
image.format = 'PNG' 

# set a fuzz on the image depending on how accurate you want to be 
image.fuzz = '10%' 

# get the image background color 
background_color = image.background_color 

# convert pixels based on their color to being transparent 
# the fuzz set above controls how accurate the conversion will be 
image.paint_transparent(background_color) 

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^