How to convert a PDF to PNG with ImageMagick “convert” or Ghostscript?

You can use one commandline with two commands (gs, convert) connected through a pipe, if the first command can write its output to stdout, and if the second one can read its input from stdin. Luckily, gs can write to stdout (… -o %stdout …). Luckily, convert can read from stdin (convert -background transparent – … Read more

How to find the dominant/most common color in an image?

Here’s code making use of Pillow and Scipy’s cluster package. For simplicity I’ve hardcoded the filename as “image.jpg”. Resizing the image is for speed: if you don’t mind the wait, comment out the resize call. When run on this sample image, it usually says the dominant colour is #d8c865, which corresponds roughly to the bright … Read more

How to force image resize and keep aspect ratio?

img { display: block; max-width:230px; max-height:95px; width: auto; height: auto; } <p>This image is originally 400×400 pixels, but should get resized by the CSS:</p> <img width=”400″ height=”400″ src=”https://i.stack.imgur.com/aEEkn.png”> This will make image shrink if it’s too big for specified area (as downside, it will not enlarge image).

Scale down to fit an image in FOP

I found this page here explaining how scaling works with XSL-FO. Essentially, this is the snippet that I used to make it work: <fo:external-graphic src=”https://stackoverflow.com/questions/6220316/url(“https://stackoverflow.com/questions/6220316/…”)” width=”100%” content-height=”100%” content-width=”scale-to-fit” scaling=”uniform” xsl:use-attribute-sets=”img”/> I found that width=”100%” was the missing piece in your own attempts. Hope this helps future visitors.

How to parse into base64 string the binary image from response?

I think part of the problem you’re hitting is that jQuery.ajax does not natively support XHR2 blob/arraybuffer types which can nicely handle binary data (see Reading binary files using jQuery.ajax). If you use a native XHR object with xhr.responseType=”arraybuffer”, then read the response array andĀ convert it to Base64, you’ll get what you want. Here’s a … Read more

How to export PDF page as an image using PDFsharp .NET library?

The answer can be found in the PDFsharp FAQ list: http://www.pdfsharp.net/wiki/PDFsharpFAQ.ashx#Can_PDFsharp_show_PDF_files_Print_PDF_files_Create_images_from_PDF_files_3 PDFsharp creates PDF files, but it cannot render them. The call Bitmap b = new Bitmap((int) pdfp.Width.Point, (int) pdfp.Height.Point, xgfx.Graphics); does not initialize any bits of the bitmap and does not copy anything from the Graphics object except for the DPI setting of the … Read more

Techniques for profiling memory in Safari desktop and iOS?

When you install the iOS SDK, a utility named Instruments is also installed. It can track all sorts of usage stats, including memory (there is even a “Leaks” template). The great thing is that it can track both the iPhone/iPad simulator and any connected iOS development device. It also, of course, can be used to … Read more

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