Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kingfisher 3.0 iOS swift RoundCornerImageProcessor white background

This is the code that I am using to set the user image which works great to actually get and set the image. I get a white outline to the picture. Any idea how to make this transparent?

let processor = RoundCornerImageProcessor(cornerRadius: 50)
self.userPhoto.backgroundColor = Colors.accent
self.userPhoto.kf.setImage(with: url, placeholder: UIImage(named: "ic_camera_alt_48pt"), options: [.processor(processor)])

Example with 50 enter image description here

like image 507
ajonp Avatar asked Jun 21 '17 11:06

ajonp


2 Answers

The format of the original image doesn't support transparency (i.e. JPEG). You must convert the image to one that does (i.e. PNG) prior to caching.

From the Kingfisher Cheat Sheet:

By default (DefaultCacheSerializer), Kingfisher will respect the input image format and try to keep it unchanged. However, there are some exceptions. A common case is that when you using a RoundCornerImageProcessor, you may always want the alpha channel. If your original image is jpg, you may want to set the png serializer instead:

let roundCorner = RoundCornerImageProcessor(cornerRadius: 20)
imageView.kf.setImage(with: url, 
    options: [.processor(roundCorner), 
              .cacheSerializer(FormatIndicatedCacheSerializer.png)]
)
like image 168
Brandon Zacharie Avatar answered Nov 15 '22 04:11

Brandon Zacharie


You don't need the RoundCornerImageProcessor

self.userPhoto.layerCornerRadius = 50
self.userPhoto.clipsToBounds = true
self.userPhoto.backgroundColor = Colors.accent
self.userPhoto.kf.setImage(with: url, placeholder: UIImage(named: "ic_camera_alt_48pt"))
like image 43
Tieme Avatar answered Nov 15 '22 05:11

Tieme