@ruyuanzhang, using a visualization tool that correctly implements s/q-form matrices, the code you’ve written should lead to correctly render epi_al2anat.nii.gz overlaid on top of the anatomical image (which means the visualization software is correctly resampling the data using the affine).
That is assuming the affine variable in your snippet is an affine matrix that maps coordinates in EPI space into anatomical space. This is the core of the question, because if you run some registration software and used the anatomical as reference, the affine matrix will map coordinates from anatomical to EPI (ie. you’ll need to invert such an affine).
Data are not touched and that is actually the rationale to include those x-forms in the NIfTI format: to avoid resamplings that make use of interpolation to calculate off-grid values (and modifying the original data).
If you want to regrid your data, then your problem is very similar to this other one Nibabel - How can we rescale a 3d image. In your case the target affine is given by the gridding you create in anatomical space.