GithubHelp home page GithubHelp logo

Problem with the tags versions about image HOT 14 CLOSED

jbzoo avatar jbzoo commented on August 16, 2024
Problem with the tags versions

from image.

Comments (14)

SmetDenis avatar SmetDenis commented on August 16, 2024

Hi Mariano,

Thanks a lot!

Yes stable tag is not released yet, because I'm develop it now.
But you can download dev version via composer.

composer require jbzoo/image:"3.x-dev"

Best regards, Denis.

from image.

mapirelli avatar mapirelli commented on August 16, 2024

Hi Denis,
i understand, thanks.

i report you a little writing mistake on line 331 in the dev version:

$cleanFilename = FS::clean($filename);
        if (!file_exists($cleanFilename)) {
            throw new Exception('Image file not forund: ' . $filename);
        }

And then i want suggest you to develop a feature that can be usefull:
The possibility to load an image from string and not only from a file, this can be usefull when we want manipulate images loaded from database. Now i extended your class and i overload the constructor in order to load the image. I want share with you these few lines of code:

/**
 * Enter description here ...
 * @author Mariano.Pirelli
 *
 */
class ImageMemory extends Image {

    public function __construct($imageString) {

        // Require GD library
        if (!extension_loaded('gd')) {
            throw new \Exception('Required extension GD is not loaded.');
        }

        if (empty($imageString)) {
            throw new \Exception('Empty image string data');
        }

        if (function_exists('getimagesizefromstring')) {
            //gather meta data
            $info = getimagesizefromstring($imageString);
        } else {
            throw new \Exception('PHP 5.4 is required to use method getimagesizefromstring');
        }

        $this->cleanup();
        $this->_mime   = $info['mime'];
        $this->_width  = $info[0];
        $this->_height = $info[1];
        $this->_image = imagecreatefromstring($imageString);
        $this->_exif   = array();
        $this->_orient = $this->_getOrientation();

        imagesavealpha($this->_image, true);
        imagealphablending($this->_image, true);

        return $this;
    }
}

Thanks for the work.
Best regards
Mariano

from image.

SmetDenis avatar SmetDenis commented on August 16, 2024

Yea, thanks.
I think it can be usefull, I will add support to new release.

But I think that saving images to database is nt good idea.

from image.

mapirelli avatar mapirelli commented on August 16, 2024

Oh yes i know...there are advantage and disadvantage..
I forgot to add the render method getImageData();

public function getImageData($format = 'png', $quality = null)
{
        if (!$this->_image) {
            throw new \Exception('Image resource not defined');
        }
        // Output the image
        ob_start();
        $mimetype  = $this->_renderImageByFormat($format, null, $quality);
        $imageData = ob_get_contents();
        ob_end_clean();

        return $imageData;
}

from image.

SmetDenis avatar SmetDenis commented on August 16, 2024

Great!

PS I changed your comments, fixed highlight of code.

from image.

mapirelli avatar mapirelli commented on August 16, 2024

Thank you very much.

I want suggest you just another thing. i hope that this can help:

I found that PHP under windows use the extension .tmp on uploaded files, included images, while others system don't use the extension.

So if i use a code like this an exception will be thrown:

$image = new Image($_FILES['name']['tmp_name']); // the temp file
$image->bestFit(800, 600)->save(); //save the temp file
copy($_FILES['name']['tmp_name'], $newPath); //copy the file 

the exception is: Undefined format. because the format is tmp.

    protected function _renderImageByFormat($format, $filename, $quality)
    {
        if (Helper::isJpeg($format)) {
        } elseif (Helper::isPng($format)) {
        } elseif (Helper::isGif($format)) {
        } else {
            throw new Exception('Undefined format: ' . $format);
        }
        return $result;
    }

so i suggest this behavior:

when the method save() is called, could be better read the image format from the mime type instead from file extension, the filename is not changed so also the format, and the error above will be prevented.

while on savaAs(), read like now the format from the file name extension.

i hope that is comprensible what i wrote.

Mariano

from image.

SmetDenis avatar SmetDenis commented on August 16, 2024

Hi Mariano,

I jsut pushed new version to 3.x-dev. Please try it and tell me what do you think.

Thanks.

from image.

SmetDenis avatar SmetDenis commented on August 16, 2024

All these features available in the 3.x version. It is stable now.
Thanks.

from image.

mapirelli avatar mapirelli commented on August 16, 2024

Hi Denis,
thanks for the new features, looks perfect.
I don't found the method to get the modified image in string format, must i use the base64 function and then convert the result ?

from image.

SmetDenis avatar SmetDenis commented on August 16, 2024

Hi,

You can use $string = $image->getBase64(<FORMAT>)
or $image->getImage() to convert string manually.

May be you can sugget me some another method to convert it to string? May be with pull request?

Best regards, Denis.

from image.

mapirelli avatar mapirelli commented on August 16, 2024

Hi,
like the base64 without convertion, the binary format is:

    /**
     * Outputs image as binary string 
     *
     * @param null|string $format  If omitted or null - format of original file will be used, may be gif|jpg|png
     * @param int|null    $quality Output image quality in percents 0-100
     * @return string
     *
     * @throws Exception
     */
    public function getImageData($format = 'gif', $quality = null) or
    public function getImageString($format = 'gif', $quality = null) or
    public function getImageBinary($format = 'gif', $quality = null)
    {
        if (!$this->_image) {
            throw new Exception('Image resource not defined');
        }
        // Output the image
        ob_start();
        $mimetype  = $this->_renderImageByFormat($format, null, $quality);
        $imageData = ob_get_contents();
        ob_end_clean();
        return $imageData;
    }

from image.

SmetDenis avatar SmetDenis commented on August 16, 2024

Hi mapirelli,

Try to use getBinary() from v3.0.2

from image.

mapirelli avatar mapirelli commented on August 16, 2024

Hi Denis, thank you very much.

from image.

SmetDenis avatar SmetDenis commented on August 16, 2024

You are welcome :)

from image.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.