• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

Converting image files to GIF

gifDB

Chevereto Noob
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