i can't explain in the right way but i think this image will help
(http://m.UploadEdit.com/ea3u/1458585415488.jpg)
void sf::Sprite::setTextureRect(const IntRect & rectangle)
http://www.sfml-dev.org/documentation/2.3.2/classsf_1_1Sprite.php#a3fefec419a4e6a90c0fd54c793d82ec2
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 :D
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.