## Posts Tagged ‘png’

### Round images to width and heights divisible by 2, by cropping

Saturday, November 10th, 2012

To make an h264 movie from a bunch of images using ffmpeg I need all the images to have size dimensions divisible by two. Here’s a little one-liner to crop a bunch of images to the nearest size divisible by 2:


for file in *.png; do convert -crop identify -format "(%[fx:w]/2)*2" $file | bcxidentify -format "(%[fx:h]/2)*2"$file | bc+0+0 $file cropped_$file; done


I suppose using mogrify would potentially be faster. But I’m not sure how to introduce the rounding.

### Convert a bunch of images into a video, batch job

Friday, October 26th, 2012

I was sure I posted this some time before, but just in case, here it is again.

My programs can easily dump jpgs, pngs, or tga image files at every frame. Sometimes it suffices to convert these to an animated GIF using imagemagick. But if there are many images and they’re all hi-res then really you need a proper video codec to get a reasonably small file. I use this ffmpeg command:


ffmpeg -f image2 -r 30 -i myimages-%04d.tga -r 30 -vcodec libx264 -sameq output.mp4


### TexMapPreview: simple texture mapping utility

Wednesday, September 21st, 2011

I posted the source and binary of TexMapPreview. It’s a little texture mapping utility I’ve been using to visualize texture maps on the meshes I deform. It takes as input a mesh (with texture coordinates) and an (texture) image. Then it can either write the visualization of the texture mapped mesh to an output file or display it in a GLUT window. Glut is the only dependency.

TexMapPreview itself can only read and write .tga image files. But, I include a bash script wrapper which uses ImageMagick’s convert tool to enable reading and writing of all sorts of file formats (.png, .jpg, .tiff, whatever convert can read/write).

### Open .tga files with alpha channel in photoshop

Monday, September 5th, 2011

Here’s the tedious step by step to open a .tga file with transparency in photoshop as if it were a .png file:

1. Open your image.tga
2. In the main menu at the top choose Layer > New > Layer from Background… then click OK
3. Open the Channels dialog: Window > Channels

You should see:

• RGB
• Red
• Blue
• Green
• Alpha (unchecked)

If you don’t see the Alpha channel then your .tga file doesn’t have one

1. Command+click on the alpha channel’s thumbnail (or select the Alpha channel and click the little dashed circle at the bottom of the channels dialog “Load channel as selection”)
2. Choose Layer > Layer Mask > Reveal Selection
3. With the layer mask selected choose Layer > Layer Mask > Apply
4. In the the Channels dialog, trash the Alpha channel

### Extract all images from a pdf as png files (at full resolution)

Friday, August 26th, 2011

Here’s a two-liner to extract all the embedded color images in a pdf and convert then to png files. pdfimages extracts the images as ppm files. But I couldn’t open these immediately on my mac with my favorite image editing tools, so I convert them with mogrify from the imagemagick suite to png files.


pdfimages original.pdf ./extracted-images
mogrify -format png ./extracted-images*.ppm


and to get rid of the ppm files


rm ./extracted-images*.ppm


### Extract full resolution image from PDF using Illustrator and Photoshop

Tuesday, July 12th, 2011

I had the problem that when kinkos scanned my artwork they gave me a PDF. This doesn’t make a whole lot of sense because the scan is a raster image. It’d be much better off in PNG or in many cases JPG. I tried just opening the PDF in Preview or Photoshop and saving as a PNG but when prompted for the resolution I wasn’t sure what to put. What was the resolution of the PDF? And what was the resolution of the embedded image? Then I tried opening the PDF in illustrator, selecting the image and pasting it as raw pixels into a new photoshop document. This didn’t work either since the image was embedded into the PDF in a scaled form so the copied image was too small. My final solution is as follows:

### In illustrator

1. Select the image object
2. Open View > Document Info > Embedded Objects
3. Record the size of the image
4. Copy the selected image

### In Photoshop

1. Create a new document (this will be the correct dimensions of the copied object, but perhaps the wrong resolution)
2. Paste the object, but as a Smart Object
3. Choose Image > Image size…
4. Enter the size of the image, previously recorded
5. Choose Layer > Flatten Image

Update: As suggested in the comments it’s much easier to use pdfimages to extract embedded images. I made a follow up post which does this then uses imagemagick’s mogrify to convert the files to pngs.

Update: Also, (see the comments), this is not even the easiest way to a get a single image from a pdf into photoshop.

### AntTweakBar GLUT example app using Xcode

Monday, October 11th, 2010

Here is a short tutorial to create a simple GLUT xcode project using the prototyping UI library AntTweakBar. I expect that you have compiled AntTweakBar as a static libary.

### Create an xcode project

Open Xcode. File > New Project. Then choose Other > Empty Project. (The dialog looks different for different versions of Xcode, so just find “Empty Project” some place).

Call your project: AntTweakBarGLUTStarter

### Add a target executable

Right-click on Targets then select Add > New Target… (or go to Project > New Target…)

Choose Cocoa > Application as the template of your new target (Don’t worry we’re not really making a cocoa app, it’s still going to be in pure GLUT. This just helps make the bundle).

Call your target: AntTweakBarGLUTStarter

Important:
Under the Build settings of your new target (Right-click on the AntTweakBarGLUTStarter target and select Get Info, then choose the Build tab), you need to remove the GCC_PREFIX_HEADER entry.

### Link to libraries

Right-click on your target and select Add > Existing Frameworks.

This will open up your target’s general info tab. At the bottom left click the “+” sign to add linked libraries. Select GLUT.framework and OpenGL.framework.

Click the “+” sign again and then “Add Other…”. Add your libAntTweakBar.a file. I always copy my external dependencies into a folder called [my xcode project]/external. So mine is located at AntTweakBarGLUTStarter/external/AntTweakBar/lib/libAntTweakBar.a

This will prompt you with some options. Just choose “add”.

### Add AntTweakBar header

I’m not sure if there is a more pleasant way to do this. I add the AntTweakBar.h file directly to my xcode project. Right-click on AntTweakBarGLUTStarter > Add > Existing Files… .

Then add AntTweakBar.h (mine is located at AntTweakBarGLUTStarter/external/AntTweakBar/include/AntTweakBar.h).

Again, just click “add” at the prompt.

### Create a main program

Right-click on AntTweakBarGLUTStarter > Add > New File.

Choose C++ file.

Call it main.cpp

Now you are ready to put whatever you want in your program. I copied the contents from the AntTweakBar GLUT example (TwSimpleGLUT.c) into main.cpp. This works almost as is. Just add at the very top you:


#ifdef __APPLE__
#define _MACOSX
#endif


### Adding an icon

You’ll see in the above screen shot that I have a beautiful dock icon for my app. This is very easy in the current setup.

Make some icon using Photoshop/Gimp whatever you like. I just save the image as a .png file and use http://iconverticons.com/ to convert it to a .icns file.

Once you have the .icns file add it to your project. I made a new folder AntTweakBarGLUTStarter/data and put my icon there: AntTweakBarGLUTStarter/data/AntTweakBarGLUTStarter.icns. So Right-click on AntTweakBarGLUTStarter > Add > Existing File.

Choose your icon file.

Again, just click “add” at the prompt.

To set this file as your icon Right-click on your target and select Get Info…

Then choose the Properties tab. Under “Icon file:” type the name of your icon file.

### Download

Source: The above is largely based off of: http://blog.onesadcookie.com/2007/12/xcodeglut-tutorial.html

### Change screenshot file format in Snow Leopard to PNG

Wednesday, June 16th, 2010

Just started working on a snow leopard machine and have been annoyed that the screenshots are saved as PDFs. To switch back to png I opened Terminal.app and issued this command:


defaults write com.apple.screencapture type png


Then you must issue:


killall SystemUIServer


to make the change take effect.

Note: You can replace png in the above with any of these: png, pdf, tiff, pict, bmp, gif, psd, sci, or tga.

source

### Vi(m) tip #5: convert list of image files into latex figures

Wednesday, November 11th, 2009

If I select and copy (CMD+C) a bunch of image files in Finder
then paste (CMD+V) in TextEdit, then recopy and paste into vi(m), I can run the follow commands to make each file into a full blown latex figure. (Of course you can also just copy and paste the list using ls on any unix/linux machine.)

For eps files:


:%s/^$$.*eps$$$/\r\\begin{figure}[tbp]\r\\centering\r\\epsfig{file=\1,width=0.9\\linewidth,clip=}\r\\caption{}\r\\end{figure}/  and for others (png here, just replace with jpg etc.):  :%s/^$$.*png$$$/\r\\begin{figure}[tbp]\r\\centering\r\\includegraphics[width=0.9\\textwidth]{\1}\r\\caption{}\r\\end{figure}/


Example:

The first one-liner substitutes:


bilapl_all_bnds_ex.eps
bilapl_all_bnds_ey.eps
trilapl_all_bnds_ex.eps
trilapl_all_bnds_ey.eps
trilapl_all_bnds_ez.eps


with this:


\begin{figure}[tbp]
\centering
\epsfig{file=bilapl_all_bnds_ex.eps,width=0.9\linewidth,clip=}
\caption{}
\end{figure}

\begin{figure}[tbp]
\centering
\epsfig{file=bilapl_all_bnds_ey.eps,width=0.9\linewidth,clip=}
\caption{}
\end{figure}

\begin{figure}[tbp]
\centering
\epsfig{file=trilapl_all_bnds_ex.eps,width=0.9\linewidth,clip=}
\caption{}
\end{figure}

\begin{figure}[tbp]
\centering
\epsfig{file=trilapl_all_bnds_ey.eps,width=0.9\linewidth,clip=}
\caption{}
\end{figure}

\begin{figure}[tbp]
\centering
\epsfig{file=trilapl_all_bnds_ez.eps,width=0.9\linewidth,clip=}
\caption{}
\end{figure}