I want to use the Facebook users Profile Picture in my Application.
I think I should use the following function, but I'm not sure if that's correct:
public function getImg() {
$img = file_get_contents('https://graph.facebook.com/'.getUser().'/picture?type=normal');
return $this->img;
}
My goal is to place the profile picture on top of another image.
I think I have to use something like this:
ImageCopy ( $picture , $source, 445, 160 , 0 , 0 , $width , $height );
To conclude... I want to use the profile picture of a user an add it on another picture, how can I do this ?
grab user profile pic using following code:
$userpic = imagecreatefromjpeg("http://graph.facebook.com/".$user_id."/picture?type=normal");
Now place in in your main photo:
$mainphoto = imagecreatefromjpeg("path/to/main/photo.jpg");
imagecopymerge($mainpic, $userpic, $x, $y, -2, -2, 55, 55, 100);
Now $mainphoto will contain the main photo and userpic on it.
you have to follow the same for all userpics you want to put on the mainphoto.
finally download the photo in server and free the memory:
imagejpeg($mainphoto, "save_as_this_name.jpg", 100);
imagedestroy($mainphoto);
I do not know php but i think this example from here may help you:
<?php
// Create image instances
$src = imagecreatefromgif('php.gif');
$dest = imagecreatetruecolor(80, 40);
// Copy
imagecopy($dest, $src, 0, 0, 20, 13, 80, 40);
// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);
imagedestroy($dest);
imagedestroy($src);
?>
Related
I'm trying to make a very simple game.
a) I let the user input his name;
b) I put this name in a canvas;
c) I generate an image (base64) whit canvas.toDataRL() and I create an image file sending the base64 URI to a php file. I'm doing it with this code:
JAVASCRIPT:
var canvas = document.getElementById("myCanvas");
var dataURL = canvas.toDataURL("image/jpeg", 0.2);
//console.log(dataURL);
// post the dataUrl to php
$.ajax({
type: "POST",
url: "upload.php",
data: {image: dataURL}
}).done(function( respond ) {
console.log(respond);
});
UPLOAD.PHP
<?php
if ( isset($_POST["image"]) && !empty($_POST["image"]) ) {
$dataURL = $_POST["image"];
$parts = explode(',', $dataURL);
$data = $parts[1];
$data = base64_decode($data);
// create a temporary unique file name
$file = "img/" . UPLOAD_DIR . uniqid() . '.png';
// write the file to the upload directory
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save this image.';
}
?>
d) Now I'd like to use this image that I've created to set the og:image tag (to share it on Facebook)! How can I do? I've honestly no idea.
Thank you!
Maybe in the OG you can put the link with <?php echo $file; ?>
I've found out the solution.
I pass the respond via get to another php page that catch the get parameter and put it in the og:image'content part.
You can debug your OG markup here: https://developers.facebook.com/tools/debug/
General information about open graph markup: https://developers.facebook.com/docs/sharing/webmasters#markup
I'm using the perl module Gtk2::WebKit to create a browser and take a screenshot of a web page. There is no problem to take a screenshot of the visible portion of the page (the window size). However, how can I take a screenshot of the full page, even the part not visible in the window?
I think this is what you're looking for. I found it on Github.
screenshot.pl - Take a screenshot
Save a page as an SVG:
screenshot.pl --type svg http://www.google.com/
Save a page as a PDF:
screenshot.pl --output cpan.pdf http://search.cpan.org/
Save an element of a page taken from an XPath query as a PNG:
screenshot.pl --output ba.png --xpath 'id("content")' http://bratislava.pm.org/
Here is my GTK2 solution to this problem:
#!/usr/bin/perl
use Gtk2 -init;
use Gtk2::WebKit;
use Data::Dumper;
my $window = Gtk2::Window->new;
my $sw = Gtk2::ScrolledWindow->new;
my $view = Gtk2::WebKit::WebView->new;
my $factor = 0;
$window->set_default_size(Gtk2::Gdk->screen_width, Gtk2::Gdk->screen_height);
$window->set_border_width(1);
$sw->add($view);
$window->add($sw);
$window ->signal_connect( 'destroy' => \&delete_event );
$view->signal_connect( 'load-finished' => \&prepare_zoom);
$view->set_full_content_zoom(TRUE);
$view->signal_connect( 'size-allocate' => \&screenshot);
$view->open('http://stackoverflow.com/questions');
$window->show_all;
Gtk2->main;
#####################################
sub delete_event {
Gtk2->main_quit;
return FALSE;
}
#####################################
sub prepare_zoom {
$adj = $sw->get_vadjustment();
$factor = $adj->page_size/$adj->upper;
$view->set_zoom_level($factor);
}
sub screenshot {
return unless defined($window->window) && $factor>0;
my ($width, $height) = $window->window->get_size;
my $sWidth=$width*$factor;
my $gdkpixbuf = Gtk2::Gdk::Pixbuf->new ('rgb', 0, 8, $width, $height);
$gdkpixbuf->get_from_drawable($window->window,
undef, 0, 0, 0, 0, $width, $height);
$gdkpixbuf->save ("screenshot.jpg", 'jpeg', quality => 100);
#Gtk2->main_quit;
return FALSE;
}
This code works, but I'm not a GTK2 / Webkit expert, so I'm sure it can be written in a better way.
The idea behind it is simple:
Load the page
Get full page size and visible page size, then calculate the scale factor needed to see the full page content
Scale the page using that scale factor
Grab the screenshot
NOTES
Depends where you want to apply it, the scale factor calculation may need some corrections
You can crop the screenshot (to remove the blank areas) adjusting the values passed to get_from_drawable.
i am trying to create a fb app using the user profile pic. app will generate a new image that image should post to user feed. I am trying to use "source" but it is not working. This is not giving full image. It gives thumbnails instead of posting full image. Here is my code
$canvas = imagecreatetruecolor($crop_width,$crop_height);
imagecopy($canvas,$currentimage,0,0,0,0,$crop_width,$crop_height);
$test = $data['user_id'].'test.jpg';
imagejpeg($canvas, $test,100);
$new = imagecreatetruecolor(150,150);
imagecopyresized($new,$canvas,0,0,0,0,150,150,$w,$crop_height);
$resize1 = $data['user_id'].'resize1.jpg';
imagejpeg($new, $resize1 ,100);
$source1 = 'black.jpg';
$background = imagecreatefromjpeg($source1);
$resize = imagecreatefromjpeg($resize1);
imagecopy($background,$resize,100,250,0,0,150,150);
$output = $data['user_id'].'output.jpg';
imagejpeg($background,$output,100);
echo '<div align="center"><img src="'.$output.'"></div>';
unlink($test);
unlink($resize1);
$access_token = "ABCDEFGHIJKLM";
$graph_url ="https://graph.facebook.com/me/feed?access_token=".$access_token."&method=post&source=http://www.Google.es/images/srpr/nav_logo39.png&message=logo";
$user_permissions = json_decode(file_get_contents($graph_url));
print_r($user_permissions);
Please help me this solves me to create a perfect fb app.
I am using the TinyMCE image manager plugin Archiv.
I configured as recommended
in config.base.php, if I set
'upload_path' => '/var/www/example/template/',
'upload_uri' => 'http://www.example.com/template/',
it works fine, but if I use:
'upload_path' => $upload_path,
'upload_uri' => $upload_uri,
where
$dir = $client->agencycode; //which is string
$upload_path = "/var/www/example/template/$dir/";
$upload_uri = "http://www.example.com/template/$dir/";
The plugin work properly except uploading files.
I can create directory, list directory, delete files. The only thing do not work is upload a files.
Is there anyway or anything need to configure in order to make uploads work?
Thanks.
If you have problems with a Black background while uploading transparent png files, change the function create_png(...) in Archiv->php->connector to the following code:
function create_png($file, $width, $height, $pic_new_width, $pic_new_height, $thumb_width, $thumb_height){
#fetch the extention from the file
$file_path = substr($file,0,strrpos($file,DIRECTORY_SEPARATOR));
$file_name = substr($file,strlen($file_path)+1, (strrpos($file,".")-(strlen($file_path)+1)));
$file_ext = substr($file,strrpos($file,"."));
#create the picture
$pic = imagecreatetruecolor($pic_new_width, $pic_new_height);
$source = imagecreatefrompng($file);
// enable alpha blending on the destination image.
imagealphablending($pic, true);
// Allocate a transparent color and fill the new image with it.
// Without this the image will have a black background instead of being transparent.
$transparent = imagecolorallocatealpha( $pic, 0, 0, 0, 127 );
imagefill( $pic, 0, 0, $transparent );
$imgcpyrsmpld = imagecopyresampled( $pic, $source, 0, 0, 0, 0, $pic_new_width, $pic_new_height, $width, $height );
imagealphablending($pic, false);
// save the alpha
imagesavealpha($pic,true);
header('Content-type: image/png');
if(version_compare(PHP_VERSION, '5.1.2', '<')){
$imagepng = imagepng($pic, $file_path.DIRECTORY_SEPARATOR.$file_name.$file_ext);
}
else{
$imagepng = imagepng($pic, $file_path.DIRECTORY_SEPARATOR.$file_name.$file_ext, 0);
}
$imagedestroy = imagedestroy($pic);
list($width, $height) = #getimagesize($file);
#create the thumb
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
$source2 = imagecreatefrompng( $file );
// enable alpha blending on the destination image.
imagealphablending($thumb, true);
// Allocate a transparent color and fill the new image with it.
// Without this the image will have a black background instead of being transparent.
$transparent = imagecolorallocatealpha( $thumb, 0, 0, 0, 127 );
imagefill( $thumb, 0, 0, $transparent );
$imgcpyrsmpld2 = imagecopyresampled( $thumb, $source2, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height );
imagealphablending($thumb, false);
// save the alpha
imagesavealpha($thumb,true);
header('Content-type: image/png');
if(version_compare(PHP_VERSION, '5.1.2', '<')){
$imagepng2 = imagepng($thumb, $file_path.DIRECTORY_SEPARATOR.$file_name.'_thumb'.$file_ext);
}
else{
$imagepng2 = imagepng($thumb, $file_path.DIRECTORY_SEPARATOR.$file_name.'_thumb'.$file_ext, 0);
}
$imagedestroy2 = imagedestroy($thumb);
}
Finally, I used the 'images' plugin instead.
As other mentioned, there is no documentation for this plugin.
I tryed to open an existing file modify it by including text and then send it to the user (render). What I recognised is that the font size only changes for the saved version of the file. If I only render it, the font size is ignored.
Why is this happening? What do I do wrong? Can I do something against it?
Greetings,
-lony
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
// fetch allready styled pdf
$pdf = Zend_Pdf::load('img/voucher/gift_vouchers.pdf');
// set default color and font with size
$style = new Zend_Pdf_Style();
$style->setFillColor(new Zend_Pdf_Color_Html('#c34827'));
$style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 9);
// fetch first page
$page = $pdf->pages[0];
// set default style to page
$page->setStyle($style);
$page->drawText('To_', 72, 10);
$page->drawText('From_', 72, 200);
$page->drawText('For_Chrismas', 1, 100);
$page->drawText('For_Message Lorem Ipsum isries.', 72, 520);
$page->drawText('1231233123', 72, 520);
$page->drawText('23/12/2010', 72, 520);
// only for DEBUG to show difference
$pdf->save('img/voucher/voucher-'.Zend_date::now()->getTimestamp().'.pdf');
$this->getResponse()->setHeader('Content-type', 'application/pdf', true);
$this->getResponse()->setHeader('Content-disposition', 'inline; filename=' . $this->_pdfName . '.pdf', true);
$this->getResponse()->setBody($pdf->render(false));