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

        $config->append(array(
                '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'
        );

        // 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;
        }

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

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

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

        foreach ($images as $key => $value) {
            $filename = $this->_mixer->getCoverFile($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;
    }
public function setCover($config)
    {
        $config = new AnConfig($config);

        $config->append(array(
                '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'
        );

        // 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;
        }

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

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

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

        foreach ($images as $key => $value) {
            $filename = $this->_mixer->getCoverFile($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;
    }
public function setCover ( $ config ) { $ config = new AnConfig ( $ config ) ; $ config -> append ( array ( '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' ) ; // 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 ; } if ( $ this -> persisted ( ) ) { $ this -> _mixer -> removeCoverImage ( ) ; } $ images = $ this -> _mixer -> resizeCoverImage ( $ image ) ; $ this -> _mixer -> set ( 'coverFilename' , md5 ( uniqid ( '' , true ) ) . '.' . $ mimetypes [ $ config -> mimetype ] ) ; $ this -> _mixer -> set ( 'coverMimetype' , $ config -> mimetype ) ; $ sizes = array ( ) ; $ files = array ( ) ; foreach ( $ images as $ key => $ value ) { $ filename = $ this -> _mixer -> getCoverFile ( $ 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 ; }
Set the cover.

@param array $config The cover options [data,orientation,mimetype]
Set the cover .