Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can the loading method directly support the loading of image content? #28

Closed
franklee0902 opened this issue Apr 21, 2018 · 14 comments
Closed

Comments

@franklee0902
Copy link
Contributor

For example, after generating the QRCode image, I want to create ImageObject directly with the
QRCode image content. Otherwise, I can only save it locally and then read the local file, wasting IO

@joseluisq
Copy link
Owner

@joseluisq
Copy link
Owner

Or do you want to load an image resource?

@franklee0902
Copy link
Contributor Author

Yes, I want to load an image resource directly.Because the QRcode image has been generated in memory,I want to synthesize it to other image.

@joseluisq
Copy link
Owner

Well, due the library doesn't support image resource loading, we can add it as new feature.

@joseluisq
Copy link
Owner

Did you try to use Canvas?
Here an example:

$qr = new Image();
$qr->load('/img.png')
$qr->scale(0.5)
// preserve the image resource because save function destroy it by default
$qr->preserve()
$qr->save('/new_qr.png')

$img2 = new Image();
$img2->load('/img2.png')
$img2->scale(0.1)
$img2->save('/new_img2.png')

// use canvas to merge them as a new image
$canvas = new Canvas();
$canvas->append([
  $qr,
  $img2,
]);
$canvas->draw();
// Canvas extends from Image, so you can use all image methods too.
$canvas->save();

Tell me later how it was.

@franklee0902
Copy link
Contributor Author

    $promotionImage = new Canvas($backgroundFigure);
    $promotionImage->append(
        [
            $headerImage,
            $qrcodeImage,
            $backgroundTextImage,
            $nickNameText,
        ]
    );
    $promotionImage->toJPG()->draw()->output();

@franklee0902
Copy link
Contributor Author

Yes,I used Canvas.

@franklee0902
Copy link
Contributor Author

use SimpleSoftwareIO\QrCode\Facades\QrCode;

private function generateQrcode(){
$this->stream = QrCode::format('png')
->merge($this->logoAbsolutePath, .2, true)
->size($this->size)
->margin($this->margin)
->generate($this->content);
}

I used "simplesoftwareio/simple-qrcode" to generate QrCode image resource,and I want to load image resource like this:

/**
* Load an Image from stream.
*
* @param string Image stream
* @return void
*/
public function loadFromStream($stream)
{
$this->from = 'stream';

    if (Utils::isJPGResource($stream)) {
        $this->extension = 'jpg';
        $this->type = IMAGETYPE_JPEG;
    }

    if (Utils::isPNGResource($stream)) {
        $this->extension = 'png';
        $this->type = IMAGETYPE_PNG;
    }

    $this->resource = imagecreatefromstring($stream);
    $this->width = $this->boxWidth = imagesx($this->resource);
    $this->height = $this->boxHeight = imagesy($this->resource);

    return $this;
}

@franklee0902
Copy link
Contributor Author

But I don't know how to add to the library is better.

@joseluisq
Copy link
Owner

I used "simplesoftwareio/simple-qrcode" to generate QrCode image resource,and I want to load image resource like this:

/**

  • Load an Image from stream.

  • @param string Image stream

  • @return void
    */
    public function loadFromStream($stream)
    {
    $this->from = 'stream';

    if (Utils::isJPGResource($stream)) {
    $this->extension = 'jpg';
    $this->type = IMAGETYPE_JPEG;
    }

    if (Utils::isPNGResource($stream)) {
    $this->extension = 'png';
    $this->type = IMAGETYPE_PNG;
    }

    $this->resource = imagecreatefromstring($stream);
    $this->width = $this->boxWidth = imagesx($this->resource);
    $this->height = $this->boxHeight = imagesy($this->resource);

    return $this;
    }

Yeah, that's the idea. I have created an issue #29 to do that.

@franklee0902
Copy link
Contributor Author

Oh, that's great!

@joseluisq
Copy link
Owner

Done aa286bd
I will publish the new release in coming hours. But you can it directly from the master branch https://packagist.org/packages/joseluisq/gimage#dev-master

@joseluisq
Copy link
Owner

The new release v3.0.5 have published. Check out #29

@franklee0902
Copy link
Contributor Author

I got it, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants