I tried the process from this post resize partition on an image file. I didn't succeed in understanding why it goes wrong in my case.
I produced a 8GB image using dd. The image contains two partitions.
I map the image with losetup -P /dev/loop0 $image-file.
Then:
resize2fs /dev/loop0p2 4000M
resize2fs 1.44.1 (24-Mar-2018)
Resizing the filesystem on /dev/loop0p2 to 1536000 (4k) blocks.
The filesystem on /dev/loop0p2 is now 1536000 (4k) blocks long.
e2fsck -f /dev/loop0p2 ->>> clean
parted /dev/loop0
(parted) resizepart 2 4000MB` ; print gives 4GB partition
(parted) quit
partprobe -s /dev/loop0
lsblk /dev/loop0
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 7,5G 0 loop
├─loop0p1 259:2 0 256M 0 loop
└─loop0p2 259:3 0 3,5G 0 loop
root@O3:/home/m/tmp# e2fsck -f /dev/loop0p2
e2fsck 1.44.1 (24-Mar-2018)
The filesystem size (according to the superblock) is 1903360 blocks
The physical size of the device is 1154143 blocks
**Either the superblock or the partition table is likely to be corrupt**!
Abort? yes
The partition resize with parted creates the inconsistency, because after resize2fs the e2fsck is clean.
Any ideas to explore to be able to shrink the image file?
parted /dev/loop0...