I need to create new html pages with PHP. What I need is to get a new html page with a canvas inside.
At this moment I capture the canvas from another page with html2canvas.
I need this canvas to become the background of the new html page, or just a 100% width 100% height picture.
What I have with PHP is this, but I need to capture the picture or just the canvas on fly, and then make something like this:
<?php
$file = file_get_contents("example.html");
file_put_contents("example.html", $file);
?>
How can I do this? thanks.
From what I understand you're trying to take a screenshot of a page, then use that as the background of another new created page in PHP.
Take a look at this for taking screen shots: Website screenshots using PHP
Once you have your screenshot taken, just use something such as
$newpage = 'example.html';
$contents = file_get_contents($newpage);
$contents = "<html><style>background-image: '<?php echo //Your Saved Screenshot ?>'</style></html>";
file_put_contents($newpage, $contents);
Related
So,I'm trying to automate downloading images from picjumbo.com site.So far most things worked like finding img src and find it's image etc.But when I try to download the image all I get is an html file(open those files with notepad++ to view it).How do I download the file after loading that page? I'm putting my code below.Everything works except getting that final image! :(
How do I download that image ?
file Download page : http://picjumbo.com/download/?d=IMG_3642.jpg
How do I save that image after the page load??
thanks!
<?php
include("simple_html_dom.php");
$file = "http://picjumbo.com/";
$files = file_get_contents($file);
$html = new simple_html_dom();
$html->load($files);
foreach($html->find('img[class=image]') as $element){
$img_src = explode('/',$element->src);
$img_src = explode('-',$img_src[5]);
$img = $img_src[0];
$url = 'http://picjumbo.com/download?d='.$img.'.jpg';
copy($url, 'images/'.$img);
}
The URL redirects to a page that uses Javascript to start a separate download. If you watch what happens in the Network tab of the browser's Developer Tools, you'll see that the actual URL of the image is:
http://picjumbo.com/wp-content/themes/picjumbofree/run.php?download&d=$img.jpg
The reason you're getting an HTML page when you try to download that link instead of the image is because that page is an HTML page, not an image. If you click on it, it takes you to an HTML page rather than to an image. Now once that page is loaded, it redirects you to downloading the image using this on line 12 of the HTML code:
<meta http-equiv="refresh" content="0; url=http://picjumbo.com/wp-content/themes/picjumbofree/run.php?download&d=IMG_3642.jpg">
So the URL image is this:
http://picjumbo.com/wp-content/themes/picjumbofree/run.php?download&d=IMG_3642.jpg
In order to download this image, you'd have to gather this HTML page into a variable, and parse through it in some way to grab the URL from this, and then use file_get_contents() to download the image. To parse through this, you could use something like SimpleHTMLDOM to read it in, or since you're just looking for the one tag, if it appears consistently in the document, you could just pull out line 12 then use some creative substr() action to get the URL.
I want to print only the image in a HTML page.
I used
function printImg(){
var URL = "image.png";
var W = window.open(URL);
W.window.print();
}
But executing the code, whole page prints rather the image. Are there any method to print only the image? Pls guide me.
Thanks.
create one print.css that hide all other unwanted divs except the image
If you heard about CSS Media types then you can achieve your desired task with this technique.
Example:
Define Media Type Print and then add a css class.noprint with a css rule display:none; in your css file like given below:
#media print {
.noprint{ display: none }
}
And then apply this class on the elements you don't want to print.
SEE AN EXAMPLE
Hope this will help you a lot.
Use
W.print();
instead of
W.window.print();
W.window makes reference to the parent's window of the pop-up.
Besides this you may consider using an empty page with a window.print triggered on load, instead of your current method which is not waiting for the image to be ready.
== EDIT ==
This can't be done. You can't modify browser settings (i.e. printer settings) from JavaScript
Finally I thought of convert my result to PDF format and print using FPDF Library
You can create an image element then append it to the DOM.
function printImg() {
var img = document.createElement( "img" );
img.src = "image.png";
document.body.appendChild( img );
}
i might not be clear with my question title but here is the code..
<?php
$filename = 'myfile.htm';
ob_start();
<?PHP
<div id='test'>my original value</div>
?>
$htmlcontent = ob_get_contents();
file_put_contents("$filename", $htmlcontent);
ob_end_clean();
so this code will eventually create a new file and with the text 'my original value
is it possible if i want to alter the div's value through javascript/jquery before it could be transferred to the file?
why am i doing this? because i would eventually be adding a jquery graph library and want to save it to the file..
later using wkhtmltopdf to generate a pdf version of that html page..
No; You'll have to display the page along with all of the javascript you want to use. Then you create a form to gather the contents of the page (after its been manipulated by your graph library) and post it back to PHP, where it can be saved to file.
Hmm, well you can try one thing. I don't know how the content of myfile.htm looks like, but you can try to load this content with something like DOMDocument, use the loadHTML method, and getElementById.
so:
<div id="test1">value</div>
could be retrieved with
// pseudo
$dom = new DOMDocument::loadHTML('myfile.htm');
$dom->getElemenyById('test1');
$dom->saveHTMLFile('etc ..
execute a $.post and 'manipulate' the existing myfile.htm and overwrite it.
cheers
I know there has to be a better way to do this.
Currently I have a php script which will generate a random image from a certain directory when called.
I have div's calling the background.php file in the stylesheet under the div's background setting
background:url(randomimagescript.php);
There are a lot of little div's on this page right now, all calling separate random image php scripts... is there a way I could use a variable when calling the file, so I can just use one script? I still need to have good styling control over the image, so i'm not sure if there is a better option than calling the script as a background image for a div.
If anyone has any ideas, let me know!
try this (it might not be optimal):
background:url("randomimagescript.php?folder=myfolder");
and in randomimagescript.php:
<?php
$folder = #_$REQUEST['folder'];
$url = "galleries/$folder/thumbs/image.jpg"; // ie, compose image
http_redirect($url); // go and find the image.
?>
It sounds a little crazy, but you could actually make your stylesheet be generated by PHP, and just fill in the blank, so to speak.
background:url(<? echo pickRandomImage(); ?>)
set the background for all divs once on the page using jquery
var image = <?echo randomimagescript.php?>
$("div").css('background', 'url('+ image+ ')');
I have standard text links which all say "Full View". When clicked these links send out php in this form: http://mysite.com/fullview.php?myimage=30
Basically there's thumbnailed images and text links that say full view. I'd like for fullview.php to capture the myimage variable, and display it as a full sized image. Meaning, a blank page (fullview.php) displaying the image. Sounds likes javascript to me.
How do you put the javascript into fullview.php to capture the variable and display it as a full sized image?
myimage=30 can be any number example: myimage=942
Thanks for any help, Darrell
If you just want to display a full-sized view of images, you may consider using a JavaScript image display library, such as fancybox. You can probably achieve what you want with the autoDimensions: true option, which is the default.
I think you are passing image id(myimage=30) to fullview.php. So you can simply get it with $_GET['myimage'] in fullview.php. Now you can use this imageid to get image and just display it with HTML <img> tag.
For example in fullview.php
if( isset( $_GET['myimage'] ) ) {
$imageid = $_GET['myimage'];
echo "<img src='/images/folder/path/" . $imageid . ".jpg' />";
}