Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS thumbnail always square #17

Closed
CricketLaChica opened this issue Oct 17, 2023 · 7 comments
Closed

iOS thumbnail always square #17

CricketLaChica opened this issue Oct 17, 2023 · 7 comments
Assignees

Comments

@CricketLaChica
Copy link
Contributor

On iOS, the thumbnail function always results in a square aspect ratio. I noticed on VideoEditor.swift, line 111, width and height are being set to the same variable. Could this be made in error? In the Android files, it's implemented properly.

@dragermrb dragermrb self-assigned this Oct 17, 2023
@CricketLaChica
Copy link
Contributor Author

When I change the aspect ratio to something that’s not a square, the thumbnail ends up being distorted. Anyone else having this issue? It happens to me on iOS.

@dragermrb
Copy link
Owner

I'll probably fix it next week.

@CricketLaChica
Copy link
Contributor Author

@dragermrb Thank you sir!

@CricketLaChica
Copy link
Contributor Author

@dragermrb Hey man, I know you’re super busy. I’ll see if I can fix it also. Looks like the issue is with VideoEditor.swift right?

@dragermrb
Copy link
Owner

You need to fix cropToBound() function:

func cropToBounds(image: UIImage, width: Double, height: Double) -> UIImage {
let cgimage = image.cgImage!
let contextImage: UIImage = UIImage(cgImage: cgimage)
let contextSize: CGSize = contextImage.size
var posX: CGFloat = 0.0
var posY: CGFloat = 0.0
var cgwidth: CGFloat = CGFloat(width)
var cgheight: CGFloat = CGFloat(height)
// See what size is longer and create the center off of that
if contextSize.width > contextSize.height {
posX = ((contextSize.width - contextSize.height) / 2)
posY = 0
cgwidth = contextSize.height
cgheight = contextSize.height
} else {
posX = 0
posY = ((contextSize.height - contextSize.width) / 2)
cgwidth = contextSize.width
cgheight = contextSize.width
}
let rect: CGRect = CGRect(x: posX, y: posY, width: cgwidth, height: cgheight)
// Create bitmap image from context using the rect
let imageRef: CGImage = cgimage.cropping(to: rect)!
// Create a new image based on the imageRef and rotate back to the original orientation
let image: UIImage = UIImage(cgImage: imageRef, scale: image.scale, orientation: image.imageOrientation)
return image
}

@CricketLaChica
Copy link
Contributor Author

@dragermrb I've opened a PR. Hopefully, this helps!

@dragermrb
Copy link
Owner

Thanks @CricketLaChica !

Merged and released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants