Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Call to a member function setOffset() on null #12

Open
Gabriel416 opened this issue Apr 1, 2018 · 0 comments
Open

Call to a member function setOffset() on null #12

Gabriel416 opened this issue Apr 1, 2018 · 0 comments

Comments

@Gabriel416
Copy link

Hello I am having issues with the Decoder giving me the error of 'Call to a member function setOffset() on null'

I am receiving a base64 string from the front end, converting that string to a gif image and then writing that image to a folder. Everything seems to work fine until I hit the Decoder. here is my code below.

        public function video(Request $request) {

                $date = Carbon::now()->format('m-d-Y');

                // split the string on commas
                // $data[ 0 ] == "data:image/png;base64"
                // $data[ 1 ] == <actual base64 string>
                $data = explode( ',', $request->image);
                $image = Image::make($data[1])->encode('gif');
                $fileName = uniqid() . '.' . 'gif';
                $location = 'uploads/' . $fileName;
                $image->save($location);
                    

                $gifStream = new FileStream($location);

                 //Create Decoder instance from MemoryStream
        
                $gifDecoder = new Decoder($gifStream);


                //Create Renderer instance
                 
                $gifRenderer = new Renderer($gifDecoder);


                $gifRenderer->start(function (FrameRenderedEvent $event) {
                    //Convert frame index to zero-padded strings (001, 002, 003)
                    $paddedIndex = str_pad($event->frameIndex, 3, '0', STR_PAD_LEFT);
                    // Write frame images to directory
                    imagepng($event->renderedFrame, "uploads/frame{$paddedIndex}.png");
                });
                return 'ok';
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant