public function setPortrait($config)
    {
        $config = new AnConfig($config);

        $config->append(array(
                'rotation' => 0,
                'mimetype' => 'image/jpeg',
        ));

        if ($config->url) {
            $config->append(array(
                'data' => file_get_contents($config->url),
            ));
        }

        $config->mimetype = strtolower($config->mimetype);

        //the allowed mimetypes
        $mimetypes = array('image/jpeg' => 'jpg','image/png' => 'png','image/gif' => 'gif');

        //force mimetype to jpeg if invalid
        //@TODO is this wise ?? No it isn't, but until we find a more reliable method to detect mimetypes
        if (!isset($mimetypes[$config->mimetype])) {
            $config->mimetype = 'image/jpeg';
        }

        if ($config->data) {
            $data = $config->data;

            if (empty($data)) {
                return false;
            }

            $config->append(array(
                'image' => imagecreatefromstring($data),
            ));
        }

        $image = $config->image;

        if (empty($image)) {
            return false;
        }

        $rotation = $config->rotation;

        switch ($rotation) {
            case 3:
                $rotation = 180;
                break;

            case 6:
                $rotation = -90;
                break;

            case 8:
                $rotation = 90;
                break;

            default :
                $rotation = 0;
        }

        if ($rotation != 0) {
            $image = imagerotate($image, $rotation, 0);
        }

        if ($this->persisted()) {
            $this->_mixer->removePortraitImage();
        }

        $images = $this->_mixer->resizePortraitImage($image);
        $this->_mixer->set('filename', md5(uniqid('', true)).'.'.$mimetypes[$config->mimetype]);
        $this->_mixer->set('mimetype', $config->mimetype);

        $sizes = array();
        $files = array();

        foreach ($images as $key => $value) {
            $filename = $this->_mixer->getPortraitFile($key);
            $sizes[$key] = $value['size'];
            $files[$filename] = AnHelperImage::output($value['data'], $config->mimetype);
        }

        imagedestroy($image);
        $this->_mixer->setValue('sizes', $sizes);
        $this->_pending_files[$this->_mixer] = $files;

        return true;
    }