Example #1
0
/* crop image */
Imlib_Image crop(Imlib_Image *source_image, int x, int y, int w, int h)
{
  Imlib_Image new_image; /* construct filtered image here */
  Imlib_Image current_image; /* save image pointer */
  int width, height; /* source image dimensions */

  /* save pointer to current image */
  current_image = imlib_context_get_image();

  /* get width and height of source image */
  imlib_context_set_image(*source_image);
  width = imlib_image_get_width();
  height = imlib_image_get_height();

  /* get sane values */
  if(x < 0) x = 0;
  if(y < 0) y = 0;
  if(x >= width) x = width - 1;
  if(y >= height) y = height - 1;
  if(x + w > width) w = width - x;
  if(y + h > height) h = height - x;

  /* create the new image */
  imlib_context_set_image(*source_image);
  new_image = imlib_create_cropped_image(x, y, w, h);

  /* restore image from before function call */
  imlib_context_set_image(current_image);

  /* return filtered image */
  return new_image;
}
Example #2
0
static
void mainwin_update_bg_pixmap(MainWin *mw)
{
	Imlib_Image tmp;
	XSetWindowAttributes wattr;
	Pixmap dummy;
	
	if(mw->bg_pixmap != None)
		imlib_free_pixmap_and_mask(mw->bg_pixmap);
	
	imlib_context_set_image(mw->background);
	tmp = imlib_create_cropped_image(mw->x, mw->y, mw->width, mw->height);
	imlib_context_set_image(tmp);
	
	imlib_context_set_drawable(mw->window);
	imlib_render_pixmaps_for_whole_image(&mw->bg_pixmap, &dummy);
	
	wattr.background_pixmap = mw->bg_pixmap;
	XChangeWindowAttributes(mw->dpy, mw->window, CWBackPixmap, &wattr);
	XClearArea(mw->dpy, mw->window, 0, 0, 0, 0, False);
	
	imlib_free_image();
}
Example #3
0
static inline PyObject * 
ImageObject_cropped_image(PyObject* self, PyObject *args)
{
    int x, y, w, h;
    if (!PyArg_ParseTuple(args, "iiii:cropped_image", &x, &y, &w, &h)){
        return NULL;
    }
    
    imlib_context_set_image(((ImageObject *)self)->image);
    int maxw = imlib_image_get_width();
    if(maxw < w){
        w = maxw;
    }
    int maxh = imlib_image_get_height();
    if(maxh < h){
        h = maxh;
    }

    Imlib_Image image = imlib_create_cropped_image(x, y, w, h);
    if(!image){
        return NULL;
    }
    return (PyObject *)ImageObject_New(image);
}