• Welcome to the Chevereto User Community!

    Here, users from all over the world come together to learn, share, and collaborate on everything related to Chevereto. It's a place to exchange ideas, ask questions, and help improve the software.

    Please keep in mind:

    • This community is user-driven. Always be polite and respectful to others.
    • Support development by purchasing a Chevereto license, which also gives you priority support.
    • Go further by joining the Community Subscription for even faster response times and to help sustain this space

Converting image files to GIF

gifDB

Chevereto Member
This might go a little beyond tech support, but I thought I might ask.
My image hosting website is exclusively for gif images, so I'd like to automatically convert if someone uploads a jpg or png.

I tried writing the following to class.upload.php:
Code:
    public function process()
    {    
        if($this->valid_data()) {
            $this->extension = $this->get_true_extension($this->mime);        

            if($this->extension == 'jpg') {
                require_once('class.imageconvert.php');
                $this->ImageConvert = new ImageConvert($this->working, $this->extension, $this->img_upload_path.'temp_'.generateRandomString(256));
                unset($this->working); unset($this->extension);
                $this->working = $this->ImageConvert->out;
                $this->extension = 'gif';
            }

and the following to class.imageconvert.php:
Code:
class ImageConvert {
    
    function __construct($file, $extension, $destination)
    {

        if($extension=='jpg') {
            $temp_image = $this->ImageCreateFromjpeg($file);
            unlink($file);
            // Now we convert gd to png
            imagegif($temp_image, $destination);
            $this->out = $destination;
        }
    }

It uploads the image, but then returns an error and doesn't actually save the finished file to the images directory.
Instead, in the image directory, I get temporary files like this:
http://demo.chevereto.com/images/LgVwb.png

Any tips for how I might accomplish converting files to gif?

Thanks
 
You are in the correct way but you need to do a different thing here...

This code will never work:
PHP:
if($extension=='jpg') {
            $temp_image = $this->ImageCreateFromjpeg($file);
            unlink($file);
            // Now we convert gd to png
            imagegif($temp_image, $destination);
            $this->out = $destination;
        }

If you don't make this:
PHP:
private function ImageCreateFromjpeg($filename) ....

And in class.upload.php this conditional:
PHP:
if($this->extension == 'jpg') {

Should be:
PHP:
if($this->extension !== 'gif') {

Tips:
1. Use the construct to call the ImageCreate functions according to each extension (make a switch).
2. The ImageCreateFromBmp is because GD doesn't have a direct bmp > png but other extensions are more easy to work. Look the example 2 http://php.net/manual/en/function.imagegif.php

Hope you find your way 😉
 
Back
Top