TImageEnView not able to display some .jpg file - delphi

pImageEnView.IO.LoadFromFileJPEG(pFileName) doesnt not display some of the .jpg images but when i use pImageEnView.IO.LoadFromFileAuto(pFileName) the image are visible this also happened when i was using pImageEnView.IO.LoadFromFileBMP(pFileName) for .bmp file

The explanation that fits the symptoms is that the file format does not match the file extension. Perhaps you have a .jpg file that is really a Windows bitmap file. Or some other format.
Debug and diagnose this by looking at the files in a hex editor. All common image file formats begin with a header that identifies the format.

Related

What is the header Content type suppose to do?

So i have this ASP.Net app and i want to allow the client to have the option to download an xlsx file, im using the HttpContext.Response to set the Content Type "application/xlsx" and the Content-Disposition sets the file name with the extension .xlsx, the download works correctly.
if I change the file name to .pdf then the file is downloaded as a pdf, when I checked the developer tool network response the Content Type was "application/xlsx" and in another test I change the name fileto .png and the file was downloaded as an image (it did not work, but it was shown as an image)
So what is the content type supposed to do, does it bring some sort of security how do i make sure that the user can only downloads the file associated to the content type?
Im using response.BinaryWrite()
A content type indicates what type of content is being transmitted over http regardless of the content name. For example as you already have tested, you can transmit a pdf file naming it as a .png file.
It is the browser or the operating system that is representing a file with the name .png as an image to you. Another software would treat a pdf file with .png name as a pdf file.
The name of the file matters after the download is complete. But the software that is handling the download (in this case a web browser) actually may need to know the original media type. And you might want to write client side codes that would need to know what type of file is being transferred from the server regardless of the file name.

imagemagick convert pdf with text(no scan) to gibberish

I am processing pdf files with imagemagick to images but this particular file is processed to some really gibberish stuff
To simplify stuff I am doing simple
convert file.pdf out.jpg
Just an idea is that it is mix of text pdf and image pdf and this could cause troubles. Can you help?
Pages of document which are in text are converted to this gibberish, last page which is actually scan is fine
this is the link to the original
file
EDIT: I found out that also files without combination of text and scan are causing issues, actually files which contain text data, not scanned image. So the question is how to setup imagemagick to convert pdf with pure text to image without getting this output
Problem was with ghostscript 9.22,
update to 9.23 helps

Get Thumbnails from any file even ones that are not in the thumbs.db

I need to extract Thumbnails from files in a Folder.
I tried with this example but it doesn´t always work.
It gives me thumbnails of images and PDF files, but not of Word, Excel, Text, OpenOffice, etc. files.
Edit: What I mean with "It doesn't work" is "It doesn't return the image I expect. It returns the icon of the application used to open the file.
Edit 2: Windows Explorer does show me thumbnails of the files I mention "not working" (.xls, .doc, , .ppt, .odt, .ods)
I think you are mistaken. Not all .doc and .xls files are saved with thumbnails. Certainly .txt files are not saved with thumbnails.
I downloaded the demo code and tried it out. It successfully shows thumbnails for .doc and .xls that showed thumbnails in Explorer. It shows standard icons for those files that do not have thumbnails when viewed in Explorer.
Here is a tool witch reads Thumbs.db file extracting images from it i hope it helps (source provided )
https://sites.google.com/site/delphibasics/home/delphibasicsprojectreleases/thumbsdbviewer
I don't know why the code you posted doesn't work properly it should...

(rails) how to validate whether an uploaded .txt file is not, say, an image file?

I have a upload text file field, and with it I plan to save the file somewhere and then store the location of the file in a database. However, I want to make sure the file they uploaded is a .txt file, and not, say, an image file. I imagine this happens in the validation step. How does one validate such a thing? Also, how do you get the filename of the uploaded file? I could always just check if it said '.txt' but for future reference knowing how to validate without just the filename would be helpful.
Trying to validate the contents of a file based on the filename extension is opening the door for major hackerdom. It's trivial to change the extension and upload the file.
If you are on a Mac/Linux/Unix-based system the OS "file" command is the standard because it looks inside the file for key bytes that flag file types. http://en.wikipedia.org/wiki/File_(Unix) I'm not sure what's available for Windows, but this might help: Determine file type in Ruby
One way of doing it, the simple way really, would be to pass the file through an image loader, preferably one that handles multiple common formats, and see if it throws an error.
The other way is to manually check the file header for common image format headers. For example, .bmp files start with BM. Other formats have their own specific markings you can use.

Create thumbnail from Adobe Illustrator file?

Does anybody know how to create a thumbnail from an Adobe Illustrator file without using Illustrator? I have a php/linux based application and I'd like to do so.
-Dave
By default, Adobe Illustrator saves files as PDF compatible. Unless the file was saved in a strange way, you should be able to use ImageMagick directly to generate a thumbnail. For example:
convert file.ai -thumbnail 250x250 -unsharp 0x.5 thumbnail.png
Note: If the file has multiple artboards (which are interpreted as pages as a PDF), it will generate multiple files or, if saved as a GIF, an animated GIF.
If you can save it in PDF, PS, or EPS format you may be able to manipulate it in things like ImageMagick or Ghostscript.
EDIT:
I think you can actually use ImageMagick's convert with *.ai files as well.

Resources