RandomCrop with Condition

I want to use RandomCrops, but only allow Crops that fulfill a certain condition. Something like the logic of


transform = transforms.Compose([while crop condition not fullfilled: do transforms.RandomCrop(crop_size),
                                transforms.ToTensor(),
                                ])

Is it possible to implement that somehow?

create two different transforms and apply one based on condition?