Giter Site home page Giter Site logo

API rotates image about backgroundremover HOT 6 OPEN

daslicht avatar daslicht commented on August 30, 2024
API rotates image

from backgroundremover.

Comments (6)

xzitlou avatar xzitlou commented on August 30, 2024 1

Let me check this issue too.

from backgroundremover.

xzitlou avatar xzitlou commented on August 30, 2024

Hello @daslicht , I will check the API and I will let you know once the problem is fixed.

from backgroundremover.

daslicht avatar daslicht commented on August 30, 2024

Nice ! another issue is that batch processing isnt working, I replaced curl for downloading teh images since my server has outdated openssl, thre seams to go something wrong in the get_results function

<?

use Functions as F;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ERROR | E_PARSE);

class BackgroundRemoverAPI
{

    private $headers;
    private $api_url;
    private $results_url;

//    private function download_file($url, $filename) : void
//    {
//        $curl = curl_init();
//        $url = "https://api.backgroundremoverai.com" . $url;
//        echo $url;
//        curl_setopt($curl, CURLOPT_URL, $url);
//        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//        curl_setopt($curl, CURLOPT_SSLVERSION, 3);
//        $data = curl_exec($curl);
//        $error = curl_error($curl);
//        var_dump($data );
//        curl_close($curl);
//        # Make sure destination path exists
//        $destination_path = "./processed_images/";
//        $destination_file = fopen($destination_path . $filename, "w+");
//        fwrite($destination_file, $data);
//        fclose($destination_file);
//    }

    private function download_file($url, $filename) : void
    {
        $url = "https://api.backgroundremoverai.com" . $url;
        $destination_path = "./processed_images/";

        if (file_put_contents($destination_path.$filename, file_get_contents($url)))
        {
            echo "File downloaded successfully";
        }
        else
        {
            echo "File downloading failed.";
        }

    }


    private function get_results($params)
    {

        if (isset($params->error)) {
            print_r($params->error);
            return;
        }

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $this->results_url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_decode(json_encode($params), true));
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        $content = json_decode(curl_exec($curl));
        curl_close($curl);

        if ($content->finished == false) {
            if (intval($content->queue_count) > 0) {
                print_r("queue: $content->queue_count");
            }

            sleep(5);
            $results = $this->get_results($params);
            return;
        }



        foreach ($content->files as $f) {
       
            $this->download_file($f->url, $f->filename);
        }
    }

    public function convert_files(array $file_list) : void
    {

        $post_data['lang'] = 'en';
        $post_data['convert_to'] = 'image-backgroundremover';

        foreach ($file_list as $index => $file) {
            $post_data['file[' . $index . ']'] = curl_file_create(
                realpath($file),
                mime_content_type($file),
                basename($file)
            );
        }

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $this->api_url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        $content = curl_exec($curl);
        curl_close($curl);

        $this->get_results( json_decode($content) );
        //return json_decode($content);
    }

    function __construct()
    {
        //$this->file_list = $files_list;//['/path/to/files/blah.jpeg'];
        $this->headers = array("Authorization: 08144e1b39cc41a190d691242edaad61");
        $this->api_url = "https://api.backgroundremoverai.com/v1/convert/";
        $this->results_url = "https://api.backgroundremoverai.com/v1/results/";
    }


}

//$resp = convert_files($file_list, $headers, $api_url);
//get_results($resp, $results_url, $headers);

from backgroundremover.

cfl-chenfangliang avatar cfl-chenfangliang commented on August 30, 2024

I have the same problem as you, with high probability is your image exif info contains rotating info. you can try:
from PIL import Image, ImageOps
img = Image.open('path/to/image').convert('RGB')

img = ImageOps.exif_transpose(img)

from backgroundremover.

daslicht avatar daslicht commented on August 30, 2024

thanks will try what is PIL?

from backgroundremover.

cfl-chenfangliang avatar cfl-chenfangliang commented on August 30, 2024

thanks will try what is PIL?

pythom Image library. The basic idea is to process the exif information of the image. you need to deal with it yourself if you use other language

from backgroundremover.

Related Issues (20)

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.