Example #1
0
/**
 * Create a thumbnail in memory
 * @param jpegData A pointer to a jpeg image in memory
 * @param outData A pointer to a pointer that will point to the created jpeg thumbnail
 * @return the size of the created thumbnail in bytes
 * */
int create_thumbnail (unsigned char* jpegData, int jpegDataSize, unsigned char** outData, int thumb_width, int thumb_height, int max_dimension, int thumb_quality) {
  Epeg_Image *im;
  if (thumb_quality <= 0) thumb_quality = 85;
  im = epeg_memory_open(jpegData, jpegDataSize);
  if (!im) return NULL;
  int w,h;
  epeg_size_get(im, &w, &h);

   if (max_dimension > 0) {
     if (w > h) {
       thumb_width = max_dimension;
       thumb_height = max_dimension * h / w;
     } else {
       thumb_height = max_dimension;
       thumb_width = max_dimension * w / h;
     }
  } else {
    if (thumb_width < 0) {
     // This means we want %thumb_width of w
     thumb_width = w * (-thumb_width) / 100;
    }
    if (thumb_height < 0) {
     // This means we want %thumb_height of h
     thumb_height = h * (-thumb_height) / 100;
    }
  }

  int decoded_size;
  epeg_decode_size_set(im, thumb_width, thumb_height);
  epeg_quality_set               (im, thumb_quality);
  epeg_memory_output_set         (im, outData, &decoded_size);
  epeg_encode                    (im);
  epeg_close                     (im);
  return decoded_size;
}
Example #2
0
int jpeg_thumbnail (byte *data, int insize, byte **destp, int *dest_sizep, cpoint *sizep)
   {
   Epeg_Image *im;
   int stride, valid;

   im = epeg_memory_open(data, insize);
   if (!im)
      return 0;

   sizep->x = im->in.w / CONFIG_preview_scale;
   sizep->y = im->in.h / CONFIG_preview_scale;
   epeg_decode_size_set           (im, sizep->x, sizep->y);
   epeg_quality_set               (im, 75, FALSE);
//   epeg_thumbnail_comments_enable (im, 1);
   epeg_memory_output_set (im, destp, dest_sizep);
//   epeg_encode                    (im);
   stride = (sizep->x * im->in.jinfo.num_components + 3) & ~3;

   epeg_raw                    (im, stride);
#if 1 // don't do this for now */
   valid = im->last_valid_row;
   if (valid != -1 && valid < im->in.h)
      {
      printf ("data short - shrink preview from %d to %d\n", sizep->y, valid / CONFIG_preview_scale);
      sizep->y = valid / CONFIG_preview_scale;    // shrink preview
      *dest_sizep = stride * sizep->y;
      }
#endif
   epeg_copy (im, sizep->x, sizep->y, stride);
   epeg_close                     (im);
   return valid;
   }
Example #3
0
/*
 * call-seq:
 *  to_blob()
 *
 * Returns the image data as blob and closes the image stream.
 * Please note that you can't do any further operations on the image
 * after using this method.
 */
static VALUE rb_epeg_image_to_blob(VALUE self)
{
  if(rb_iv_get(self, "epeg_file_closed") != Qfalse) {
    rb_raise(rb_eRuntimeError, "Error: closed file");
  }

  Epeg_Image *image;
  Data_Get_Struct(self, Epeg_Image, image);

  char *data;
  int size;

  epeg_memory_output_set(image, &data, &size);
  rb_epeg_image_encode_or_trim(self, image);

  VALUE blob = rb_str_new(data, size);
  free(data);

  rb_epeg_image_close(self);

  return blob;
}