sf::Image srcImg, destImg;
srcImg.loadFromFile("img_in.png");
sf::Vector2u dims = srcImg.getSize();
sf::IntRect rect = sf::IntRect(-1, -1, -1, -1);
for (sf::Uint16 x = 0; x < dims.x; x++) {
for (sf::Uint16 y = 0; y < dims.y; y++) {
if (srcImg.getPixel(x,y) == sf::Color::Transparent) continue; // don't do anything when pixel's transparent
if (rect.left == -1 || x < rect.left) rect.left = x;
if (rect.top == -1 || y < rect.top) rect.top = y;
if (rect.width == -1 || x > rect.width) rect.width = x;
if (rect.height == -1 || y > rect.height) rect.height = y;
}
}
destImg.create(rect.width-rect.left+1, rect.height-rect.top+1, sf::Color::Transparent); // resize dest img
destImg.copy(srcImg, 0, 0, rect, true); // copy defined rectangle of the source image to destination
destImg.saveToFile("img_out.png");
This is the best i could come up with atm...I'm actually working so don't have more than notepad
Hope it works or at least steers you into the direction of your solution
[UPDATE]Tested it at home just now, made some slight changes, but it works so yeah. Depending on what you want to use it for this bit of code might suit you.