Blur image with pixastic and set it as background with jquery - php

i have a problem that is bothering me form 2 days.
I'm developing a little music sharing site and i have a problem making the design for the player.
I want to apply a blurred image background to a div with CSS and with the blur begin applied on the image via JS all with pixastic js library. The problem is that pixastic gives me a HTMLImageElement witch i can't apply to a css with $('.footer').css('background', "url(" + img.toDataURL("image/png")+ ")" }); since toDataURL works only with canvas elements.
How can i do that?
My code so far is:
var img = new Image();
img.src = '<?php echo $hd ?>';
img.onload = function() {
Pixastic.process(img, "blurfast", {amount:1});
}
$('.footer').css('background', "url(" + img.toDataURL("image/png")+ ")" });
The $hd is a http url that points to an album artwork using lastfm API

I'm not sure about first argument of css method and why you dont use img.src as url of image? Try something like this:
$('.footer').css('background-image', 'url(' + img.src + ')');
Ok I found probably answer on documentation:
var options = {};
Pixastic.process(image, "action", options);
options.resultCanvas; // <- holds new canvas
So in your case it would be:
var img = new Image(),
options = {};
options.amount = 1
img.src = '<?php echo $hd ?>';
img.onload = function() {
Pixastic.process(img, "blurfast", options);
$('.footer').css('background', "url(" + options.resultCanvas.toDataURL("image/png")+ ")" });
}

Related

Kinetic JS not working in Firefox

I have used one script. My problem is script is not working in Firefox browser.
Code is here:
window.onload = function(){
var stage = new Kinetic.Stage({
container : "cantainer",
width : 400,
height : 400
});
var layer = new Kinetic.Layer();
stage.add(layer);
var con = stage.getContainer();
var dragSrcEl = null;
//image
document.getElementById("yoda").addEventListener('dragstart',function(e){
dragSrcEl = this;
});
con.addEventListener('dragover',function(e){
e.preventDefault(); //#important
});
//insert image to stage
con.addEventListener('drop',function(e){
var image = new Kinetic.Image({
draggable : true
});
layer.add(image);
imageObj = new Image();
imageObj.src = dragSrcEl.src;
imageObj.onload = function(){
image.setImage(imageObj)
layer.draw()
};
});
Check the script on link: http://jsfiddle.net/lavrton/n4w44/
Thanks for help in advance.
Add
e.preventDefault();
inside drop event listener.
Demo: http://jsfiddle.net/bk86e/

Javascript Form validation for field image uplaod?

I make a form validation with javascript for field image upload but i stuck on point of how to validate image size(width and height) through javascipt for only 600 width and 300 height image is post by form .
So guys if you have any solution are demo code share with mi .
Thanks in advance !
You can use following function in javascript side to check whether image has desired resolution or not.
If it has correct resolution than proceed with form submission otherwise show error message.
var _URL = window.URL || window.webkitURL;
$("#file").change(function(e) {
var file, img;
if ((file = this.files[0])) {
img = new Image(); // create a Image object which contain height & width property of image
img.onload = function() {
alert(this.width + " " + this.height);
};
img.onerror = function() {
alert( "not a valid file: " + file.type);
};
img.src = _URL.createObjectURL(file);
}
});

Save Google charts as a image

So after hours of websearching, googling and overflowing i can't find the solution to my problem.
I got a linechart from Google charts. I want to convert it to PNG, save it on the server en insert it into a MySQL database.
Sounds simple, but i cant get it to work. The script from this website isnt working anymore (atleast not here) http://www.battlehorse.net/page/topics/charts/save_google_charts_as_image.html -> Not working.
Second option is the old option:
$imageData = file_get_contents('http://chart.apis.google.com/chart... etc');
I cant use that because its not supported anymore and cant get some decent quality out of it.
Is there anybody here that can give a good tutorial or help for my problem?
EDIT:
I used the code from Battlehorse combined with the code from EriC.
So now i got this working to show the chart as an image in a DIV i want to save this image on the server and update the mysql to use it in the future to use it in PDF files.
When you visit the site, paste this in the console (overwriting the malfunctioning function).
function getImgData(chartContainer) {
var chartArea = chartContainer.getElementsByTagName('svg')[0].parentNode;
var svg = chartArea.innerHTML;
var doc = chartContainer.ownerDocument;
var canvas = doc.createElement('canvas');
canvas.setAttribute('width', chartArea.offsetWidth);
canvas.setAttribute('height', chartArea.offsetHeight);
canvas.setAttribute(
'style',
'position: absolute; ' +
'top: ' + (-chartArea.offsetHeight * 2) + 'px;' +
'left: ' + (-chartArea.offsetWidth * 2) + 'px;');
doc.body.appendChild(canvas);
canvg(canvas, svg);
var imgData = canvas.toDataURL("image/png");
canvas.parentNode.removeChild(canvas);
return imgData;
}
In JS it was searching for an iframe bla bla to get the svg.
To automatically save the image, you can just let the method being invoked programmatically.
document.body.addEventListener("load", function() {
saveAsImg( document.getElementById("pie_div")); // or your ID
}, false );
For saving images serverside, this post could be helpful save a PNG image server-side
Update
Posting images to PHP (index.js)
function saveToPHP( imgdata ) {
var script = document.createElement("SCRIPT");
script.setAttribute( 'type', 'text/javascript' );
script.setAttribute( 'src', 'save.php?data=' + imgdata );
document.head.appendChild( script );
}
function save() {
var canvas = document.getElementById("canvas"), // Get your canvas
imgdata = canvas.toDataURL();
saveToPHP( imgdata );
}
function drawOnCanvas() {
var canvas = document.getElementById("canvas"), // Get your canvas
ctx = canvas.getContext("2d");
ctx.strokeStyle = "#000000";
ctx.fillStyle = "#FFFF00";
ctx.beginPath();
ctx.arc(100,99,50,0,Math.PI*2,true);
ctx.closePath();
ctx.stroke();
ctx.fill();
}
drawOnCanvas(); // Test
save();
save.php
<?php
// Get the request
$data = $_GET['data'];
// Save to your DB.
?>
You can use the grChartImg library. It's a cross browser solution and supports even old versions of IE (8 and earlier).It has many features such as download image,upload to the server, show the image in a dialog etc.
For more info look at http://www.chartstoimage.eu.
i hope help you.
This is not really an answer but might be one in the future and it is nescesary if you just want the feature back. The following URL shows all the current issues and feature requests for the visualization API.
https://code.google.com/p/google-visualization-api-issues/issues/list?can=2&q=&sort=-stars+id&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary%20Stars
The more stars/votes this feature request gets, the higher the chance they will take a look at it.
I have the same issue - Save Google charts as image on server. None of answers here works for me. Finally I get solution but with some bugs(working only in Chrome browser). As base I used script from here https://gist.github.com/mpetherb/7085315 I made some changes for my project. I use jquery for importing generated graph image to to my server.
This is a graph that I want to convert to image and save google graph example id="ex0"
Script for converting to image and importing to server
<script>
function getImgData(chartContainer) {
var chartArea = chartContainer.getElementsByTagName('svg')[0].parentNode;
var svg = chartArea.innerHTML;
var doc = chartContainer.ownerDocument;
var canvas = doc.createElement('canvas');
canvas.setAttribute('width', chartArea.offsetWidth);
canvas.setAttribute('height', chartArea.offsetHeight);
canvas.setAttribute(
'style',
'position: absolute; ' +
'top: ' + (-chartArea.offsetHeight * 2) + 'px;' +
'left: ' + (-chartArea.offsetWidth * 2) + 'px;');
doc.body.appendChild(canvas);
canvg(canvas, svg);
var imgData = canvas.toDataURL("image/png");
canvas.parentNode.removeChild(canvas);
return imgData;
}
function toImg(chartContainer, imgContainer) {
var doc = chartContainer.ownerDocument;
var img = doc.createElement('img');
var myimg=img.src = getImgData(chartContainer);
//Here I am using jquery for importing decoded image to hidden.php on my server
$.ajax({
method: "POST",
url: "hidden.php",
data: { name: myimg } });
while (imgContainer.firstChild) {
imgContainer.removeChild(imgContainer.firstChild);
}
imgContainer.appendChild(img);
}
</script>
<button onclick="toImg(document.getElementById('ex0'), document.getElementById('ex0'));"
type="button" <Convert to image and upload on server></button>
// ex0 - div id of this type of google graph. If you using another type of google graph - you should change it
Don't forget include jquery to your code.
and php hidden script for receiving data from jquery method POST and saving it on server
hidden.php file
<?php
if(isset($_POST['name']))
{
$data = $_POST['name'];
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
file_put_contents('graph_temp.png', base64_decode($data));
I will notice again - works only in Chrome browser. Firefox also create image file on server but without any content (looks like firefox not support base64 encoded data)

Loading images with php and display on a gallery

I have made a javascript code that load dinamically images in a directory (php) and then display them using a jquery galery plugin.
I was unable to run the galleryView after all the pictures were loaded by the client. The single way was to use a delay command.
I donĀ“t have to tell the disadvantages of this method. Does anyone knows how to "correct" the script so that the gallery plugin is called after all the images are loaded?
<script type="text/javascript">
$("document").ready(function() {
$('#aa').load('get_fotos.php').delay(2000).queue(function() {
$('#aa').galleryView({
panel_width: 800,
panel_height: 400,
show_filmstrip_nav: false,
enable_slideshow: false,
panel_animation: 'crossfade',
frame_opacity: 1,
show_infobar: false,
frame_width: 80,
frame_height: 40,
// frame_scale: 'fit',
});
});
});
</script>
Thanks a lot
You can check this out by this:
It worked for me hope it helps.
imageArray = new Array();
imageArray[0] = 'image1.jpg'; // your image path
imageArray[1] = 'image2.jpg'; // your image path
htmldata='';
count = 0;
imgArray = new Array();
$.each(imageArray, function(i,item){
var image=new Image();
$(image).bind("load", {}, function(event) {
count++;
imageArray[i] = $(image).attr("src");
if(count==2){
$("#imageHolder").empty();
$.each(imageArray, function(j,item){
htmldata = '<img id="image'+j+'" src="' + imageArray[j] +'" />'; //create ur image tag u need to call
$("#imageHolder").append(htmldata);
});
$('#aa').galleryView({//call your bind method for plug in
});
}
});
image.src = imageArray[i];

Get images from rss on another domain(then append it)

I want to get images from a flickr rss but this code won't get them.
This is what I got up with after some help from my original qustion here : Jquery in Internet Explorer: find image problem(works in FF and Chrome)
The problem is getting the data in right format to my web page.
My page's URL is : zalastax.co.cc/pictures.html
Javascript:
$.ajax({
type: "GET",
url: "js/getflickreasy.php",
dataType: "xml",
success: function(data) {
$(data).find("item").each(function() {
var item = $(this), title, description, thumbnail;
title = item.find("title").text();
description = item.find("description").text();
thumbnail = item.find("img").attr("src");
});
}
});
PHP:
<?
header("content-type: text/xml");
readfile("http://api.flickr.com/services/feeds/photos_public.gne?id=42980910#N02&lang=en-us&format=xml");
?>
Edit: Mathews code works.
But I have a problem with appending some data.
var currentImage = 0;
//get flicker images from rss.
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=42980910#N02&lang=en-us&format=json&jsoncallback=?", function(data) {
$(data.items).each(function() {
var item = this,
title, description, thumbnail;
title = item.title;
description = item.description;
thumbnail = item.media.m;
if (currentImage % 3 === 0) {
$("#apa").append("<p>HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH</p>");
}
currentImage++;
$("#apa").append("<div id=\"div" + currentImage + "\" class=\"imageContainer pictDiv\"><img id=\"img" + currentImage + "\" class=\"bild pictImg\" src=\"" + thumbnail + "\" /></div>");
$("#bakgrund").append("<img id=\"bkg" + currentImage + "\" class=\"bgrund pictBkg\" src=\"Bilder/polaroid.png\" />");
});
$("#bakgrund").append("<img id=\"bkg" + currentImage + "\" class=\"bgrund pictBkg\" src=\"Bilder/polaroid.png\" />");
});
This code works in Google Chrome. In Firefox it retrieves the data but don't do the append.
If I try appending something else like simple text Firefox won't append that either.
It works when I'm trying it via jsfiddle.net but it doesn't when trying it via my own webpage.
You can do this without PHP, using JSONP:
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=42980910#N02&lang=en-us&format=json&jsoncallback=?", function(data) {
$(data.items).each(function() {
var item = this, title, description, thumbnail;
title = item.title;
description = item.description;;
thumbnail = item.media.m;
});
});
I made a jsFiddle demo.
http://simplehtmldom.sourceforge.net/
Easy way to fetch a website and simple interface to load specific data :)

Categories