Get Image size WITHOUT loading image into memory

If you don’t care about the image contents, PIL is probably an overkill. I suggest parsing the output of the python magic module: >>> t = magic.from_file(‘teste.png’) >>> t ‘PNG image data, 782 x 602, 8-bit/color RGBA, non-interlaced’ >>> re.search(‘(\d+) x (\d+)’, t).groups() (‘782’, ‘602’) This is a wrapper around libmagic which read as few … Read more

How to upload, display and save images using node.js and express

First of all, you should make an HTML form containing a file input element. You also need to set the form’s enctype attribute to multipart/form-data: <form method=”post” enctype=”multipart/form-data” action=”/upload”> <input type=”file” name=”file”> <input type=”submit” value=”Submit”> </form> Assuming the form is defined in index.html stored in a directory named public relative to where your script is … Read more

how to show alternate image if source image is not found? (onerror working in IE but not in mozilla) [duplicate]

I think this is very nice and short <img src=”https://stackoverflow.com/questions/3984287/imagenotfound.gif” alt=”Image not found” onerror=”this.src=”imagefound.gif”;” /> But, be careful. The user’s browser will be stuck in an endless loop if the onerror image itself generates an error. EDIT To avoid endless loop, remove the onerror from it at once. <img src=”https://stackoverflow.com/questions/3984287/imagenotfound.gif” alt=”Image not found” onerror=”this.onerror=null;this.src=”imagefound.gif”;” /> … Read more

How to compress an image via Javascript in the browser?

In short: Read the files using the HTML5 FileReader API with .readAsArrayBuffer Create a Blob with the file data and get its url with window.URL.createObjectURL(blob) Create new Image element and set it’s src to the file blob url Send the image to the canvas. The canvas size is set to desired output size Get the … Read more

Display text on MouseOver for image in html

You can use title attribute. <img src=”https://stackoverflow.com/questions/12105214/smiley.gif” title=”Smiley face”/> You can change the source of image as you want. And as @Gray commented: You can also use the title on other things like <a … anchors, <p>, <div>, <input>, etc. See: this

Image resizing client-side with JavaScript before upload to the server

Here’s a gist which does this: https://gist.github.com/dcollien/312bce1270a5f511bf4a (an es6 version, and a .js version which can be included in a script tag) You can use it as follows: <input type=”file” id=”select”> <img id=”preview”> <script> document.getElementById(‘select’).onchange = function(evt) { ImageTools.resize(this.files[0], { width: 320, // maximum width height: 240 // maximum height }, function(blob, didItResize) { // … Read more

Extract a page from a pdf as a jpeg

The pdf2image library can be used. You can install it simply using, pip install pdf2image Once installed you can use following code to get images. from pdf2image import convert_from_path pages = convert_from_path(‘pdf_file’, 500) Saving pages in jpeg format for page in pages: page.save(‘out.jpg’, ‘JPEG’) Edit: the Github repo pdf2image also mentions that it uses pdftoppm … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)