~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to ext/gd/libgd/gdparttopng.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>             /* For atoi */
 
3
#include "gd.h"
 
4
 
 
5
/* A short program which converts a .png file into a .gd file, for
 
6
   your convenience in creating images on the fly from a
 
7
   basis image that must be loaded quickly. The .gd format
 
8
   is not intended to be a general-purpose format. */
 
9
 
 
10
int
 
11
main (int argc, char **argv)
 
12
{
 
13
  gdImagePtr im;
 
14
  FILE *in, *out;
 
15
  int x, y, w, h;
 
16
 
 
17
  if (argc != 7)
 
18
    {
 
19
      fprintf (stderr, "Usage: gdparttopng filename.gd filename.png x y w h\n");
 
20
      exit (1);
 
21
    }
 
22
  in = fopen (argv[1], "rb");
 
23
  if (!in)
 
24
    {
 
25
      fprintf (stderr, "Input file does not exist!\n");
 
26
      exit (1);
 
27
    }
 
28
 
 
29
  x = atoi (argv[3]);
 
30
  y = atoi (argv[4]);
 
31
  w = atoi (argv[5]);
 
32
  h = atoi (argv[6]);
 
33
 
 
34
  printf ("Extracting from (%d, %d), size is %dx%d\n", x, y, w, h);
 
35
 
 
36
  im = gdImageCreateFromGd2Part (in, x, y, w, h);
 
37
  fclose (in);
 
38
  if (!im)
 
39
    {
 
40
      fprintf (stderr, "Input is not in PNG format!\n");
 
41
      exit (1);
 
42
    }
 
43
  out = fopen (argv[2], "wb");
 
44
  if (!out)
 
45
    {
 
46
      fprintf (stderr, "Output file cannot be written to!\n");
 
47
      gdImageDestroy (im);
 
48
      exit (1);
 
49
    }
 
50
#ifdef HAVE_LIBPNG
 
51
  gdImagePng (im, out);
 
52
#else
 
53
  fprintf(stderr, "No PNG library support.\n");
 
54
#endif
 
55
  fclose (out);
 
56
  gdImageDestroy (im);
 
57
 
 
58
  return 0;
 
59
}