TinyMCE image manager plugin "Archiv" - tinymce

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.

Related

Save GooCanvas2 to PNG file

After drawing with GooCanvas2, I'm trying to take a 'screenshot' of the canvas and save it to a .PNG file.
This script provides a very nice example using Gtk2/GooCanvas, but having converted that script to Gtk3/GooCanvas2, I get an error that I don't understand:
Write PNG...
*** unhandled exception in callback:
*** `need' is not a valid cairo_status_t value; valid values are: success, no-memory, invalid-restore, invalid-pop-group, no-current-point, invalid-matrix, invalid-status, null-pointer, invalid-string, invalid-path-data, read-error, write-error, surface-finished, surface-type-mismatch, pattern-type-mismatch, invalid-content, invalid-format, invalid-visual, file-not-found, invalid-dash, invalid-dsc-comment, invalid-index, clip-not-representable, temp-file-error, invalid-stride, font-type-mismatch, user-font-immutable, user-font-error, negative-count, invalid-clusters, invalid-slant, invalid-weight at goopng2.pl line 90.
*** ignoring at /usr/share/perl5/Gtk3.pm line 546.
The error is generated by Gtk3::Gdk::PixbufLoader->write(). I have not modified that function at all:
$surface->write_to_png_stream (sub {
my ($closure, $data) = #_;
$loader->write($data);
});
And this is the converted script:
#!/usr/bin/perl -w
use strict;
use warnings;
use GooCanvas2;
use Gtk3 '-init';
use Glib qw(TRUE FALSE);
my $window = Gtk3::Window->new('toplevel');
$window->signal_connect('delete_event' => sub { Gtk3->main_quit; });
$window->set_default_size(640, 600);
my $vbox = Gtk3::VBox->new;
$vbox->set_border_width(4);
$vbox->show;
$window->add($vbox);
my $swin = Gtk3::ScrolledWindow->new;
$swin->set_shadow_type('in');
$vbox->pack_start($swin, 1, 1, 0);
my $canvas = GooCanvas2::Canvas->new();
$canvas->set_size_request(600, 450);
$canvas->set_bounds(0, 0, 1000, 1000);
$swin->add($canvas);
my $root = $canvas->get_root_item();
my $rect = GooCanvas2::CanvasRect->new(
parent => $root,
'x' => 100,
'y' => 100,
'width' => 400,
'height' => 400,
'line-width' => 10,
'radius-x' => 20,
'radius-y' => 10,
'stroke-color' => 'yellow',
'fill-color' => 'red'
);
my $text = GooCanvas2::CanvasText->new(
'parent' => $root,
'text' => "Hello World",
'x' => 300,
'y' => 300,
'width' => -1,
'anchor' => 'center',
'font' => 'Sans 24',
);
$text->rotate(45, 300, 300);
# Create PNG
my $sb = Gtk3::Button->new_with_label('Write PNG and JPG');
$vbox->pack_start($sb, FALSE, FALSE, 0);
$sb->show;
$sb->signal_connect("clicked", \&write_png_clicked, $canvas);
$window->show_all();
Gtk3->main;
sub write_png_clicked {
my ($but, $canvas) = #_;
print "Write PNG...\n";
my $surface = Cairo::ImageSurface->create ('rgb24', 1000, 1000);
# also argb32 is available
# my $surface = Cairo::ImageSurface->create ('argb32', 1000, 1000);
my $cr = Cairo::Context->create($surface);
# make a background rectangle filled white so saved file looks same as screen
# otherwise a black background may appear, it's like pdf, if it isn't
# drawn , it will be a black background, It won't automagically pick up
# a white background on a canvas
$cr->rectangle( 0, 0, 1000, 1000 );
$cr->set_source_rgb( 1, 1, 1 );
$cr->fill;
$canvas->render($cr, undef, 1);
# this works, but see below for way to use pixbuf and jpg
# my $status = $surface->write_to_png ("$0.png");
# print "$status\n";
my $loader = Gtk3::Gdk::PixbufLoader->new;
$surface->write_to_png_stream (sub {
my ($closure, $data) = #_;
$loader->write($data);
});
$loader->close;
my $pixbuf = $loader->get_pixbuf;
print $pixbuf->get_bits_per_sample(),"\n";
print $pixbuf->get_colorspace(),"\n";
$pixbuf->save ("$0.png", 'png');
print "done png\n";
$pixbuf->save ("$0.jpg", 'jpeg', quality => 100);
print "done jpg\n";
return TRUE;
}
* unhandled exception in callback:
* `need' is not a valid cairo_status_t value; valid values are: success, no-memory, [...] at goopng2.pl line 90.
*** ignoring
at /usr/share/perl5/Gtk3.pm line 546.
By running the debugger on your code I could see that $loader->write($data) raised an exception:
need an array ref to convert to GArray
and write_to_png_stream() was not expecting this type of exception and truncated the message to the first word "need" as you can see from Glib error message at the top: `need' is not a valid cairo_status_t value ...
By some trial and error I found that I could pass the $buffer argument as an array of characters and not as a perl string:
sub write_png_clicked {
my ($but, $canvas) = #_;
print "Write PNG...\n";
my $surface = Cairo::ImageSurface->create ('rgb24', 1000, 1000);
my $cr = Cairo::Context->create($surface);
$cr->rectangle( 0, 0, 1000, 1000 );
$cr->set_source_rgb( 1, 1, 1 );
$cr->fill;
$canvas->render($cr, undef, 1);
my $loader = Gtk3::Gdk::PixbufLoader->new;
$surface->write_to_png_stream (
sub {
my ($loader, $buffer) = #_;
$loader->write([map ord, split //, $buffer]);
return TRUE;
}, $loader
);
$loader->close;
my $pixbuf = $loader->get_pixbuf;
print $pixbuf->get_bits_per_sample(),"\n";
print $pixbuf->get_colorspace(),"\n";
$pixbuf->save ("test.png", 'png');
print "done png\n";
$pixbuf->save ("test.jpg", 'jpeg', quality => 100);
print "done jpg\n";
return TRUE;
}
Edit:
To save only a part of the canvas you can pass a GooCanvasBounds parameter to the render() method:
my $bounds = GooCanvas2::CanvasBounds->new();
$bounds->x1(50);
$bounds->x2(250);
$bounds->y1(50);
$bounds->y2(250);
$canvas->render($cr, $bounds, 1);
Edit 2:
To capture a region at a specific position and a specific width and height:
my $img_width = 200;
my $img_height = 200;
my $img_x0 = 100;
my $img_y0 = 100;
my $surface = Cairo::ImageSurface->create ('rgb24', $img_width, $img_height);
$cr->translate(-$img_x0,-$img_y0);
$canvas->render($cr, undef, 1);

Adding customized straight line on x-axis by jpgrph

I would like to ask how to add the customized line into chart by using jpgraph. For example, to identify SUNDAY on date which selecting from database, the jpgraph will draw a straight line with red color on each Sunday which will be showed on x-axis.
Does anyone meet the related issue and has been solved? Please tell me, thank you.
The code of my situation:
`
$dateLocale = new DateLocale();
$dateLocale->Set('');
$file_date = date("Ymd");
$dateArray = array();
$dataSuccessful = array(); //get from db
$dataUser_not_found = array();
$dataAcc_not_activated = array();
$dataUnsuccess_others = array();
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
//Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "example";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$dateArray[] = date("d/m/Y (D)", strtotime($row["date"]));
$dataSuccessful[] = $row["login_success_count"];
$dataUser_not_found[] = $row["unsuccess_not_found"];
$dataAcc_not_activated[] = $row["unsuccess_not_activated"];
$dataUnsuccess_others[] = $row["unsuccess_others"];
}
} else {
echo "No results in this table";
}
function strBefore($string, $substring) {
$pos = strpos($string, $substring);
if($pos === false){
return $string;
}else{
return(substr($string, 0, $pos));
}
}
function strAfter($string, $substring) {
$pos = strpos($string, $substring);
if($pos === false){
return $string;
}else{
return(substr($string, $pos+strlen($substring)));
}
}
JpgraphError::SetImageFlag(false);
JpGraphError::SetLogFile('syslog');
// Create the graph.
$graph = new Graph(2560, 1320);
//initialization of the default theme
$graph->ClearTheme();
//$graph->SetScale('datlin',0,$x_max);
$graph->SetScale('datlin');
$graph->img->SetMargin(60,150,50,60);
$graph->SetShadow();
// Create the linear plot (SUCCESSFUL)
$l1plot=new LinePlot($dataSuccessful);
$l1plot->SetColor('lightblue:0.4');
$l1plot->SetFillColor("lightblue:0.7");
$l1plot->SetWeight(2);
$l1plot->SetLegend('The total number of visit (SUCCESSFUL)');
// Create the linear plot (UNSUCCESSFUL)
$user_not_found_plot = new LinePlot($dataUser_not_found);
$user_not_found_plot->SetColor('orange:1.2');
$user_not_found_plot->SetFillColor('orange#0.2');
$user_not_found_plot->SetLegend('(UNSUCCESSFUL) User not found');
$acc_not_activated_plot = new LinePlot($dataAcc_not_activated);
$acc_not_activated_plot->SetColor('green:0.8');
$acc_not_activated_plot->SetFillColor('green#0.4');
$acc_not_activated_plot->SetLegend('(UNSUCCESSFUL) Account not activated');
$others_plot = new LinePlot($dataUnsuccess_others);
$others_plot->SetColor('lightred:1.2');
$others_plot->SetFillColor('lightred#0.4');
$others_plot->SetLegend('(UNSUCCESSFUL) Others');
$graph->title->Set('log report');
$graph->xaxis->title->Set('Last 30 days');
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->setYScale(0, 'lin', 0, 2000);
/* Add the plots to the graph */
//SUCCESSFUL numbers
$graph->Add($l1plot);
//UNSUCCESSFUL numbers
$graph->AddY(0,$user_not_found_plot);
$graph->AddY(0,$acc_not_activated_plot);
$graph->AddY(0,$others_plot);
$graph->ynaxis[0]->SetColor('red');
$graph->ynaxis[0]->title->Set('The number of visit (UNSUCCESSFUL)');
$graph->ynaxis[0]->scale->SetGrace(80);
//As demo, set the specific date on x-axis
$graph->xaxis->SetLabelFormatString('d/m/Y',true);
$graph->xaxis->setTickLabels($dateArray);
// Display the graph
// Get the handler to prevent the library from sending the image to the browser
$gdImgHandler = $graph->Stroke(_IMG_HANDLER);
// Default is PNG so use ".png" as suffix
$fileName = "pic/oul207_log_".$file_date.".png";
$graph->img->Stream($fileName);
?>`
I guess you don't want a tick, so here's how to add a red vertical line:
require_once ('jpgraph/jpgraph_plotline.php');
$v_plot = new PlotLine();
$v_plot->SetDirection(VERTICAL);
$v_plot->SetColor('red');
$v_plot->SetPosition(2);
$graph->AddLine($v_plot);
Of course you'd need to calculate your sunday(s) relative to the x-axis and set the position(s) accordingly.

perl Gtk2::WebKit: how to do a full page screenshot

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.

Facebook Application - User Picture?

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);
?>

Uploading transparent images adds a black background

I am trying to make a function to handle avatar uploads.
My problem is, when I upload a transparent image, it turned everything which is transparent black after I resize it.
I have tried using the imagesavealpha() & imagealphablending() options, but the background is still turning black.
It might just be me being blind and not seeing the problem in the code, but I have no idea why it does this.
I can confirm that after the image has been moved to the image/avatars folder just after being uploaded, the background is still transparent.
this is my current code, I have been testing with .png images:
function upload_avatar(){
$base_path = SYSTEM_PATH;
if($_FILES['avatar_img']['tmp_name'] != '') {
$id = md5($this->user_id());
$filename = $_FILES['avatar_img']['name'];
$file_basename = substr($filename, 0, strripos($filename, '.')); // strip extention
$file_ext = substr($filename, strripos($filename, '.')); // strip name
$filesize = $_FILES['avatar_img']['size'];
$newfilename = $id . $file_ext;
if ($file_ext == ".jpg" || $file_ext == ".JPG" || $file_ext == ".jpeg" || $file_ext == ".png" || $file_ext == ".gif"){
if($filesize <= 153600){
move_uploaded_file($_FILES['avatar_img']['tmp_name'], $base_path."/images/avatars/" . $newfilename);
//resize image form
list($width, $height) = getimagesize($base_path."/images/avatars/" . $newfilename);
$scale_height = $height/$width;
$scale_width = $width/$height;
//Find height and width of the image
if($width > $height && $width > 150){
$width_new = 150;
$height_new = round($width_new*$scale_height);
}else if($height > $width && $height > 150){
$height_new = 150;
$width_new = round($height_new*$scale_width);
}else{
$height_new = $height;
$width_new = $width;
}
switch($file_ext) {
case ".jpg" :
case ".jpeg":
$source = imagecreatefromjpeg($base_path."/images/avatars/" . $newfilename);
break;
case ".png" :
$source = imagecreatefrompng($base_path."/images/avatars/" . $newfilename);
break;
default:
$source = imagecreatefromgif($base_path."/images/avatars/" . $newfilename);
break;
}
$destination = imagecreatetruecolor($width_new, $height_new);
imagesavealpha($destination, true);
imagealphablending($destination, true);
imagecopyresized($destination, $source, 0, 0, 0, 0, $width_new, $height_new, $width, $height);
switch($file_ext) {
case ".jpg":
case ".jpeg":
imagejpeg($destination, $base_path."/images/avatars/" . $newfilename, 85);
break;
case ".png":
imagepng($destination, $base_path."/images/avatars/" . $newfilename, 8);
break;
default:
imagegif($destination, $base_path."/images/avatars/" . $newfilename, 85);
break;
}
return $newfilename;
}else{
$this->upload_avatar = '<br />But the avatar was not updated. The avatar\'s size exceeded the 150kb limit. ';
return '';
}
}else{
$this->upload_avatar = '<br />But the avatar was not updated. The avatar must be one of the following formats: jpg, jpeg, png or gif. ';
return '';
}
}else{
return '';
}
}
Any help would be appreciated as I am going nuts looking at this now.
Thanks!
This here may be what you're looking for. The second comment contains an example of resizing pngs and gifs while preserving transparency.
p.s. I'd have added this as a comment but I don't have the rights to do that yet.