Gains from trade are possible when the world price of a good is different from the price determined by the intersection of the domestic demand (shown in blue) and the domestic supply (shown in red).
If the world price is above the domestic no-trade price, producers will expand production to supply in the export market, and the producer surplus will be larger than it would be in the absence of trade. Consumers will face higher prices and experience a smaller consumer surplus, but the gain to the producers will be larger than the loss to the consumers. The difference between the producer surplus and the consumer surplus is represented by the pink shaded area.
If the world price is below the domestic no-trade price, the consumer surplus will be larger and the producer surplus will be smaller than it would be in the absence of trade. But the gain to the consumers is greater than the loss to the producers. The difference is represented by the blue shaded area.