# Chapter 3

## CNS Image.fp7 Example Database
This chapter lists each example and a description of each example for the CNS Image.fp7 database.

### Introduction

The example database demonstrates how to use CNS Image to manipulate images directly in FileMaker. It will show you how to import and export images. It will show you how to gather information about an image. Additionally, it will demonstrate how to convert, scale, crop, rotate, reflect, transform, get a layer, and apply a QuickTime filter to an image. You can also download an image from the internet directly into a container field.

The example database goes one step further by giving you six mini solutions that are great starting points for your own solutions. You can also easily integrate these ideas into your current solutions. The mini solutions include: Screehshot Crop, Webcams, Earth View, Map Viewer, Simple Image Browser, and PDF Page Splitter.

All examples have documentation on the same layout as the example for quick reference. Examples are listed in the "Example Index" area and are sorted by the "Example Rating" which can be found at the bottom of each example.

You may want to note the "If you want to..." link in the top right corner of each layout. This link leads to a layout which has a task oriented list of things you may want to do, and links to quickly get to the information you need to know. For example, if you want to "Crop an image" then view the example "Crop" or view the function "CNSImage_Crop". There are buttons that take you to the example or the function depending on what you want to do.

### Importing

Figure 3.2 Screenshot of the "Importing" example.

There are several ways to get images into FileMaker. You can use the native capabilities to import images using only FileMaker. You can also use functionality in CNS Image to import images in ways that FileMaker cannot.

For example, you can create a dialog box that opens to a specified folder to import images from. You can even specify what type of images a user can import. You can also import an image to a container field by using a variety of different path types, including FileMaker 7 image paths.

### Exporting

Figure 3.3 Screenshot of the "Exporting" example.

The ability to export an image from a container field is somewhat limited when left to just FileMaker. However, several options are opened when using CNS Image. You can save an image to any folder with any name. So you can do interesting things like export each image in a found set to your desktop using the record ID as the file name.

### Information

Figure 3.4 Screenshot of the "Information" example.

This example demonstrates how you can use CNS Image to get information about an image such as its type, width, height, horizontal resolution, vertical resolution, depth, quality, size, path, and file name.

### Convert

Figure 3.5 Screenshot of the "Convert" example.

Using the CNSImage_Convert function, you can change the format of a image, the width and height, the resolution, the depth, the quality, and the target size. This example demonstrations how to accomplish these conversions.

### Crop

Figure 3.6 Screenshot of the "Crop" example.

This example demonstrates how to crop an image down, that is, to create a new image from part of a bigger image.

### Rotate

Figure 3.7 Screenshot of the "Rotate" example.

This example demonstrates how to use CNS Image to rotate an image.

### Reflect

Figure 3.8 Screenshot of the "Reflect" example.

This example shows you how to flip an image horizontally, vertically, or both.

### Filter

Figure 3.9 Screenshot of the "Filter" example.

This is where CNS Image can get a bit interesting because you can, for the first time that we know of, manipulate an image while still being in the FileMaker Pro environment. Never before could you change the hue of an image, or brighten or darken an image.

For example, say you have a picture that looks nice, but you want the colors to pop out more. Simply take a trip through the filter function and max out the saturation. Maybe you have a picture of a family member and you want to give it that old "Sepia" look. Not a problem. Just apply the "Color Tint" quicktime filter using the "Sepia" preset.

You can even use the filter function to tweak your graphical user interface images right in your database.

### URL

Figure 3.10 Screenshot of the "URL" example.

This example demonstrates the ability to download an image from the internet and put it directly into a container field. You simply give the plug-in a url and it will download the image and put it in the field you want it to. No importing is necessary. No temporary file is needed. No special tricks. Just a URL and the plug-ins takes care of the rest.

For some interesting uses of this function, take a look at the "Mini Solutions" that we have created for the example database including: "Webcams", "Earth View", and "Map Viewer".

### Transform

Figure 3.11 Screenshot of the "Transform" example.

The transform function allows you to pick 4 points of your image to adjust how the image is drawn. With it you can skew an image, stretch an image, or even squish an image.

### Screenshot Crop (Mini Solution)

Figure 3.12 Screenshot of the "Screenshot Crop" mini solution.

This example takes a snapshot of a given layout and then crops the image to the correct size based on the actual size of window content. It also demonstrates just cropping out a portion of a layout based on field bounds.

The basic trick is to enter preview mode, copy, and then paste the resulting image into a container field. You can then use CNS Image to crop it to the needed size.

### Webcams (Mini Solution)

Figure 3.13 Screenshot of the "Webcams" mini solution.

This "Mini Solution" is a simple webcam viewer. You can choose a category from the pull down menu on the top left, and then click a link in the portal to view the web cam picture.

This example includes several interesting ideas such as downloading an image that changes at set intervals such as every minute or every day. While the image is downloaded, we actually set the container field to a text string to show the download progress. After the image is downloaded, you have the option to automatically rotate and flip it based on field values. We also create a 25 pixel thumbnail icon after the image is downloaded just for good measure.

We have included a decent range of images to download from daily cartoons, famous places, photos of the sun that were taken within the last hour by NASA, and even the current weather for the entire USA. These are all images that are available free on the internet, so keep in mind that any of the images may change, may be temporarily down, or may no longer be offered by their respective servers.

### Earth View (Mini Solution)

Figure 3.14 Screenshot of the "Earth View" mini solution.

This "Mini Solution" uses the "Earth and Moon Viewer" website located at http://www.fourmilab.ch/earthview/vplanet.html to grab generated images that show day and night regions of the Earth at this moment. There are many different variables that you can tinker with to get a wide variety of images.

You can also use different image types for the Earth as well as the Moon. In addition, you can change the view point and the date and time for an image.

### Map Viewer (Mini Solution)

Figure 3.15 Screenshot of the "Map Viewer" mini solution.

This example retrieves a dynamically created map from the TIGER Map Server of the U. S. Census Bureau. For an overview of the system, take a look at http://www.census.gov/geo/www/tiger/tigermap.html. To view a map on the site, visit http://tiger.census.gov/cgi-bin/mapbrowse-tbl.

The Map Viewer example allows you to select a location via a "Quick Lookup" portal. You can then change the attributes of the map for roads, bounds, and labels that are shown. We have also built zooming and panning (moving) into the solution.

Keep in mind that the system is based on information from 1990 and 1998, so it is somewhat old. It does, however, help demonstrate that you can build a map browser inside of FileMaker with very little work and the use of the CNSImage_GetFromURL function.

The TIGER maps are public domain, so this service is free. However, because the data is old it may only be partially useful. The TIGER website also makes it quite clear that the service is not meant to be a full fledged map server the likes of MapQuest or Maporama, or Google Maps.

Both Mapquest.com and Maporama.com offer commercial solutions that can be integrated into FileMaker in a fashion similar to, if not exactly like, this example.

### Simple Image Browser (Mini Solution)

Figure 3.16 Screenshot of the "Simple Image Browser" mini solution.

This "Mini Solution" demonstrates a simple image browser. Using FileMaker, you can import a folder of images. You can then navigate through them with the forward and backward buttons. You can click an image to view detail for the image. You can then edit the image by using the buttons to rotate, apply filter, flip, and crop. If you are using the OS X version of FileMaker, you can use the "Set Mac Desktop" button to set the desktop picture to the currently selected image. Lastly, you can export your edited image.

### PDF Page Splitter (Mini Solution)

Figure 3.17 Screenshot of the "PDF Page Splitter" example.

This example takes a PDF and splits it into jpegs. It includes a script that will iterate through each page of the PDF and save them in a portal. The end result is one JPEG image record for each page of the original PDF. The script uses the CNSImage_GetLayer function and renders each page at 72dpi. You can also render pages at 300dpi if needed.

### Custom Functions

Figure 3.18 Screenshot of the "Custom Functions" example.

This example simply lists a few custom functions that are used in this database as well as a few that may come in handy that are not actually used in this example database. If you are using FileMaker Developer, you can view and edit Custom Functions. If you are just using FileMaker Pro, you can use Custom Functions, but you cannot edit them.

FileMaker introduced Custom Functions with FileMaker Developer 7. Custom functions allow a developer to create their own functions using any functions available to them in the calculation engine. This includes normal FileMaker functions, but also includes any Plug-in functions that are installed as well.