There can't be too much difference in the gasket diameter if it's the same (equivalent) filter. The gaskets between your old and the new should both cover the same turf. Some are slightly wider than others (thickness between OD and ID) ..but they have to share the same area a good bit (minor exceptions exist).
Your # doesn't work with the Wix site directly ..but it works with Baldwin (which calls it a NAPA silver)
The B301 in Wix (just to get gasket sizes) which says Subaru on the Baldwin site
Part Number: 51334
UPC Number: 765809513341
Principal Application: Acura (88-05), Chevrolet Spectrum (85-88), Dodge (91-96), Geo (89-93), Ford (88-96), Honda (72-05), Hyundai (89-05), Isuzu (85-04), Kia (01-05), Mercury (87-91), Mitsubishi (89-98), Subaru (87-05), John Deere, Kioti, Kobelco, Komatsu, Kubota, Onan, Toro & Yanmar Diesel
All Applications
Style: Spin-On Lube Filter
Service: Lube
Type: Full Flow
Media: Paper
Height: 3.194
Outer Diameter Top: 3.252
Outer Diameter Bottom: Closed
Thread Size: 20X1.5 MM
By-Pass Valve Setting-PSI: 8-11
Anti-Drain Back Valve: Yes
Gasket Diameters
Number O.D. I.D. Thk.
Attached 2.475 2.173 0.233
B227 (spec'd for "others" i.e. not Subaru) in Wix
Part Number: 51064
UPC Number: 765809510647
Principal Application: Bolen, Case, Hitachi, Jacobsen, I-R, John Deere, Kubota, Vermeer, Yanmar, Kia, Hyundai Transmissions
All Applications
Style: Spin-On Lube Filter
Service: Lube/Transmission
Type: Full Flow
Media: Paper
Height: 2.944
Outer Diameter Top: 3.243
Outer Diameter Bottom: Closed
Thread Size: 20X1.5 MM
By-Pass Valve Setting-PSI: 16
Anti-Drain Back Valve: Yes
Gasket Diameters
Number O.D. I.D. Thk.
Attached 2.475 2.173 0.233
Are you sure you have the correct filter