Image upload script more cleaner and secure using php 7 oop style.
To elaborate on the answer from Stexxe...


  it can have connection to database ($this->connect of your Image class) as dependency


A database class is different from all other classes. It cannot be created any time on demand. It has to be created only once, connect to a database, and hold this connection all the time. Otherwise numerous connections from the same script will crash your database server. 

So it has to be:

class ImageMapper{

    private $connect;

    public function __construct($connect)
    {
        $this-&gt;connect = $connect;
    }


and called like this:

$dbh = new Db();
$connect =  $dbh-&gt;connect();

$image = new Image($connect);



  manipulation images classes should not expose any information about their inner workings 


Among other things, it means that error reporting should never reveal the actual error to a site user. Therefore you should never ever do anything like die($error) -- which also makes the whole try..catch business misplaced in this code.  So it should be:

public function upload_image($filename, $image_name)
{
    $sql = "INSERT INTO images (img, image_name) VALUES (?, ?)";
    $this-&gt;connect-&gt;prepare($sql)-&gt;execute([$filename, $image_name]);
}


whereas a possible exception thrown by PDO must be caught elsewhere. Learn more from my article on PHP error reporting.

Some other stuff has also been fixed, mostly your extremely confusing way assigning a filename, when you are adding, removing and re-adding the directory name. Some useless variables like $directory and $filename are also removed.