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

Caption with media #17

Closed
Hip0 opened this issue Apr 21, 2014 · 6 comments
Closed

Caption with media #17

Hip0 opened this issue Apr 21, 2014 · 6 comments

Comments

@Hip0
Copy link

Hip0 commented Apr 21, 2014

Hello,
I actually use this API for SnapChat. It works perfectly, so thank to the creator and contributor but how we do for add a text with a media (video or image) ?

It will can be very useful to have a caption !

So, if someone can help me, thank a lot !

@AppliedEllipsis
Copy link

On our old web interface we used an jquery html5/canvas tool for drawing and text over images, like a paint tool. For video you can do similar, but serverside transcode the overlay with ffmpeg.

@Hip0
Copy link
Author

Hip0 commented Apr 24, 2014

Hi,
I did that and it's perfect !
Thank's :)

@Hip0 Hip0 closed this as completed Apr 24, 2014
@trankil12
Copy link

Hipo could you show me the result ? i have same problem

@Hip0
Copy link
Author

Hip0 commented Apr 26, 2014

Hi,

I use PHP to create a new image with text that i delete after. I don't have tried video because i don't need.

You can find my script annotated following and a final resulat after 😃

//Function for generate a random string (name of tmp image with text)
function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $randomString;
}

// It's for the font
putenv('GDFONTPATH=' . realpath('.'));

// Name of font to use (without .ttf). It's placed in the same directory of your .php
$font = 'GOTHIC';

$type = "img";
$file = "http://xxx.com/xx.jpg";

$snapchat = new Snapchat($_POST['pseudo'], $_POST['password']);
if (empty($snapchat->auth_token)) {$error = "Error";}
else {
    if ($type=='img') {
        $img = imagecreatefromjpeg($file);
        list($width, $height, $type, $attr) = getimagesize($file);

        $white = imagecolorallocate($img, 255, 255, 255);
        $black = imagecolorallocatealpha($img, 0, 0, 0, 40);

        //We create a rectangle with a opacity  (0.4) black. The rectangle is in the middle of the image and the height is 5% of the image source.
        imagefilledrectangle($img, 0, $height/2 , $width, ($height/2 + 0.05*$height) , $black);

        //We add a text with the font selected. The size is 3.5% of image.
        imagettftext($img, (0.035*$height), 0 , 20, ($height/2 + 0.04*$height), $white, $font, "Blablabla");

        $new_file = "tmp/". generateRandomString() . ".jpg";
        imagepng($img, $new_file); //we save the new image in /tmp with a random name

        $id = $snapchat->upload(
        Snapchat::MEDIA_IMAGE,
        file_get_contents("http://xxx.com/" . $new_file)
        );

    }

        $snapchat->send($id, array('friend'), 8); //we send the image

        unlink($new_file); //we delete the image with text
}

4zrac4cj3o

@trankil12
Copy link

awesome thanks you so much !!

@trankil12
Copy link

if you whant the caption text at the bottom of the pics

//We create a rectangle with a opacity  (0.4) black. The rectangle is in the middle of the image and the height is 5% of the image source.
    imagefilledrectangle($img, 0, $height/1.20 , $width, ($height/1.2 + 0.05*$height) , $black);
    //We add a text with the font selected. The size is 3.5% of image.
    imagettftext($img, (0.035*$height/1.20), 0 , 20, ($height/1.2 + 0.04*$height), $white, $font, $_POST['caption']);

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

3 participants