html, css, execute javascript from a gif file - php

I would like to know if it's possible to execute javascript from embedded .gif file . I can make rewrite to a php file to seem as a gif file and execute the code from there but I'm not faimilar with css/html therefore I was wondering if there is any trick to make seem there is embedded a picture but to execute javascript . I tried img src attribute but is not working as the browser seems to consider it just a simple picture...

GIF compression is lossy and is not suitable for code. However, the javascript hacker Jacob Seidelin implemented something very similar using pngs: http://blog.nihilogic.dk/2008/05/compression-using-canvas-and-png.html

Not directly answering your question, but you can embed JavaScript into SVG. Although not most browsers support SVG, but most SVG viewers support JavaScript.

Related

PHP use canvas (html5) to copy and then upload the copied picture to server

Is it possible for html5 canvas to be used has a very strong way to upload jpg, gif and png (converted to jpg) files to a server ? Normally we would do something like this http://hungred.com/useful-information/secure-file-upload-check-list-php/ and some other measures to prevent any code in any image file to be found, changed, executed, etc
But in this case, using canvas, the only thing we are doing is a copy of the pixels, right ? So the copied image, wouldn't have any malicious code in it...
Am i right ?
Could something like this http://www.fabiobiondi.com/blog/2012/10/upload-images-from-the-user-hard-driveto-an-html5-canvas-easel-js-application/ be safer ?
Is your end goal to prevent malicious code in the file?
Then using client-side Javascript isn't really a serious option, as it can be freely manipulated by the user.
If you want to be super paranoid, you could copy the image on server side using GD or ImageMagick. That would also remove any and all Metadata from the image, which is often a good thing - images come often with much more information than the original author would want to see in the open.

Can I convert all files with jquery file upload to jpg?

I'm using the jquery file upload script and it's working really well so far. The last obstacle I have is I only want to use jpg images for my website but allow users the option of uploading gif, png, or jpg.
I'm assuming I need to alter or add some additional methods to the upload.class.php file to accomplish this.
Has anyone done this before and if so is this the correct file to modify?
You will need to write some pretty tough conversion functions if you want to implement it in pure JavaScript and you'll be limited to modern browsers that support FileAPI and FileReference. Also the conversion function you'll have to write would manipulate the files at the binary level and will have to respect some pretty strict file structures as specified by GIF/JPEG/PNG standards specifications.
As i recall SWFUpload (a Flash - ActionScript - JavaScript library) has this functionality embedded, you can specify the format in which it should send the file to the server but it only applies if you wish to use the resizing function which sends a resized version of the original file to the server but it has some downsides.

PNG from CSS using PHP?

I'd like to ask whether its possible to take a bit of CSS on a page with a PHP extension, and add the PHP header to define the page as a PNG, and have a dynamic image? From what I've heard this isn't possible, but if it isn't, is there a way easier than the conventional method of creating a PHP image?
Edit*
To elaborate, I want to do something like draw a bordered 200x200p box in CSS with styling and HTML, and have this HTML/CSS box on a .PHP page, and get this page to become a PNG image with the .PNG extension using the PHP header tag.
Thank You!
Karan
You can make use of wkhtmltopdf which can convert html to pdf using webkit (qtwebkit) which supports CSS properly. There even exists a PHP binding for it.
You can then convert the PDF file to a PNG (e.g. with ImageMagick) and serve it from within PHP.
Related: Website screenshots using PHP
If I understand your question properly, I am not sure how this would be possible using only PHP but you could use ImageMagick on server side to convert the HTML page to a png.

Is there a way to output html div to an image using php?

I have a div on my page which I want to output to a jpeg file. Is this possible using PHP?
I know there's the GD library for creating images in PHP but I'm not sure if it can do what I want. Because I also want to put a barcode on the image (I used a jQuery plugin to do this on the html page) .
Is this possible (if it's possible can you give me an idea how to implement it) or is there a better approach to this? Thanks!
As far as I know the functionality you want is not supported by GD. You might want to search for a library that does that. The problem is that the browser renders the HTML and CSS, but GD would need to know how to parse and render HTML and CSS (and Javascript) in order to turn HTML into an image. It might be a better idea, depending on what you really want to do, to create an image in GD and stick it in the HTML DIV, and then you won't have to do any conversion.
If there is a way to export a section of HTML to an image in a browser, then you could use PHP to control a server-side browser and export it that way. It would be a lot more work, but it's definitely possible.
It can't be done the way you want it. Instead you can draw the image based on the data you have.
You say it's bar code... so I guess this would be a good start.

How to save webpage as a image file using PHP?

I want to save webpage as image file or i want to take snapshot of an webpage using PHP. Just like firefox extension Fireshot doing.
Check out http://browsershots.org/ and Webkit2Png
You'll need to render the page with something. If you really want to only use php, i suggest you HTMLTOPS, wich render the page and output it in a ps file (ghostscript), then, convert it in a .jpg, .png, .pdf.. can be little slower with complex pages (and dont support all the CSS).
Else, you can use wkhtmltopdf to output a html page in pdf, jpg, whaterver.. Accept CSS2.0, use the webkit (safari's wrapper) to render the page.. so should be fine. You have to install it on your server, as well..
Source: Website screenshots using PHP
Like others have said, it would be difficult to do in PHP alone. However, there is an easy-to-use cross-platform tool called CutyCapt that does exactly what you need. The best part about this tool is that it's stand-alone and doesn't depend on anything else.
You cannot do this with pure PHP, try forking a browser like Mozilla with headless mode and let it handles taking snapshot of the page.

Categories