If The image is illegal then possession and publication of it is also illegal, just like child porn
IIRC not true, at least the idea that it's all dealt with the same as child porn.
An image can be legal in context and private possession (IE a photo of two consenting adults getting it on), but might be illegal to share without consent, a photo might be legal between two consenting adults but be illegal to share (or at least "publish") even with consent (IIRC BDSM photos often fall into this group). And photos that were taken before a change in the law might be legally ok if the law did not retroactively and explicitly make them illegal as long as you don't reproduce it or share it.
As you say child porn is always illegal, but (and with legal stuff there is always a but), the line between what might be considered child porn and something that is legal can, in some very limited circumstances be blurred. IIRC there are a few BBFC passed films where an underage actor is briefly nude and because the film is BBFC approved it is legal to own*, but using screenshots and clips out of context for it can be illegal. The same applies to some books and pictures where it is "just" nudity in a work of art that was officially published and never banned, IIRC there is for example an album from the 70's with airbrushed naked girl used as part of the cover art, I know of it it (it was something like 10 years before I was born) because I remember the fuss that happened when the organisation that blocks child porn categorized it as such and proceeded to block Wikipedia (back when wiki was fairly new) because they'd got a low res image of the cover used in context on the page about the album.
Then there were the likes of the page 3 girls where the law ended up having to be tightened up because photos were taken to be published on their 18th birthday - IIRC that quickly got an amendment to the law but the original images are legal as they were legal when published.
Basically even what might be thought of as "clear cut" isn't always with the law as they don't necessarily make stuff illegal to the point where you face prosecution for things that were previously legal when they were produced or you did them. It's why so many of the historical sexual offences that the police deal with seem to have "light" sentences that don't make sense today, it's because they're being dealt with under the laws and sentencing guidelines that were in place at the time of the offence (IIRC it's a bit of a nightmare for the judges as they're in some cases using legal guidelines and laws that are 40 years out of date and they need additional training for what might be the only case they ever deal with under those laws).
Sorry going off topic a bit here, but the law is complex, especially when it comes to photos and film, and it's something I've ended up with a bit of an interest in mainly because I started paying attention to how the BBFC made decisions, and various "video nasty" type scares. I've ended up reading an awful lot of the BBFC case studies** on their site about controversial films, or films where the rating and edits have changed over time and to be honest it's actually interesting to see how a film that was banned outright due to an idiot politician getting confused about the title got an uncut 15 many years later, or how a film that was passed at one rating in the 80's might get a higher one now due to language/current guidance (IIRC the study for Watership Down suggests they might have given it a higher rating today as it's been recognised as a bit much for it's current one under todays guide).
*I think there were a handful in the 70's, some of which got DVD's releases and/or are still available on legal streaming services (IIRC there is a Romeo and Juliet with an under age Juliet's bare breasts).
**Seriously they are interesting in a lot of cases, as they can go into the political and cultural circumstances around the ratings and discussions internally and externally regarding the proposed and final ratings, and in the case of sequels or later rereleases how it had changed.