Handling images
-
Greetings I'm building a website that has an automate engine to display pictures. There is a menu that lets you choose the event. The directories are organized like this: - root -- Weddings --- WBlaBla1 ---- Pic1 ---- Pic2 ---- PicN --- WBlaBla2 ---- Pic1 ---- Pic2 ---- PicN --- SomeOtherTypeOfEventWithTheSameStructureHasPreviously -- SomethingElse The purpose is to sell the pictures, so it will have a cart shop. The problem is that I have the pictures in very high resolution, and I want to prevent the users from accessing the pictures in this format (i.e. 1807x1772). I know that PHP can handle this (i.e. display thumbnails) but the thing is that, with time, the events will be more and more, and this consumes space in the server, and the space is rented, offcourse. So I had the idea of writting a C++ application that converts ALL the pictures in a directory to a low resolution version AND with a water mark, that way the sysadmin could convert the pictures before uploading them to the server. What I would like to ask is how to do this in C++, I mean, not search the pictures nor that sort of things, but how to lower the resolution and add the water mark to them. The pictures are all in JPG format. Best regards hint_54
-
Greetings I'm building a website that has an automate engine to display pictures. There is a menu that lets you choose the event. The directories are organized like this: - root -- Weddings --- WBlaBla1 ---- Pic1 ---- Pic2 ---- PicN --- WBlaBla2 ---- Pic1 ---- Pic2 ---- PicN --- SomeOtherTypeOfEventWithTheSameStructureHasPreviously -- SomethingElse The purpose is to sell the pictures, so it will have a cart shop. The problem is that I have the pictures in very high resolution, and I want to prevent the users from accessing the pictures in this format (i.e. 1807x1772). I know that PHP can handle this (i.e. display thumbnails) but the thing is that, with time, the events will be more and more, and this consumes space in the server, and the space is rented, offcourse. So I had the idea of writting a C++ application that converts ALL the pictures in a directory to a low resolution version AND with a water mark, that way the sysadmin could convert the pictures before uploading them to the server. What I would like to ask is how to do this in C++, I mean, not search the pictures nor that sort of things, but how to lower the resolution and add the water mark to them. The pictures are all in JPG format. Best regards hint_54
Th easiest way I know of (on Windows) is to use GDI+ to load and save the images. A simple stretchblt to a smaller, proportioned size is all that's necessary...load, resize, and save.
-
Th easiest way I know of (on Windows) is to use GDI+ to load and save the images. A simple stretchblt to a smaller, proportioned size is all that's necessary...load, resize, and save.
-
Greetings I'm building a website that has an automate engine to display pictures. There is a menu that lets you choose the event. The directories are organized like this: - root -- Weddings --- WBlaBla1 ---- Pic1 ---- Pic2 ---- PicN --- WBlaBla2 ---- Pic1 ---- Pic2 ---- PicN --- SomeOtherTypeOfEventWithTheSameStructureHasPreviously -- SomethingElse The purpose is to sell the pictures, so it will have a cart shop. The problem is that I have the pictures in very high resolution, and I want to prevent the users from accessing the pictures in this format (i.e. 1807x1772). I know that PHP can handle this (i.e. display thumbnails) but the thing is that, with time, the events will be more and more, and this consumes space in the server, and the space is rented, offcourse. So I had the idea of writting a C++ application that converts ALL the pictures in a directory to a low resolution version AND with a water mark, that way the sysadmin could convert the pictures before uploading them to the server. What I would like to ask is how to do this in C++, I mean, not search the pictures nor that sort of things, but how to lower the resolution and add the water mark to them. The pictures are all in JPG format. Best regards hint_54
Here ya go...a holiday present :) (I ripped the GetEncoderClsid() right out of the GDI+ docs
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytesImageCodecInfo\* pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size); if(size == 0) return -1; // Failure pImageCodecInfo = (ImageCodecInfo\*)(malloc(size)); if(pImageCodecInfo == NULL) return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for(UINT j = 0; j < num; ++j) { if( wcscmp(pImageCodecInfo\[j\].MimeType, format) == 0 ) { \*pClsid = pImageCodecInfo\[j\].Clsid; free(pImageCodecInfo); return j; // Success } } free(pImageCodecInfo); return -1; // Failure
}
...
// Resize an 640x480 image to 320x240 // (I already know this source image is 640x480 - In real life use // SrcBitmap.GetWidth() and SrcBitmap.GetHeight() to get an image's dimensions Gdiplus::Bitmap SrcBitmap(L"D:\\\\Source\\\\Images\\\\sony-cybershot.jpg", FALSE); Gdiplus::Bitmap DstBitmap(320,240,SrcBitmap.GetPixelFormat()); Graphics DstGraphics(&DstBitmap); DstGraphics.DrawImage(&SrcBitmap, 0, 0, 320, 240); CLSID jpgClsid; GetEncoderClsid(L"image/jpeg", &jpgClsid); DstBitmap.Save(L"D:\\\\Source\\\\Images\\\\sony-cybershot\_test.jpg", &jpgClsid, NULL);
-
Here ya go...a holiday present :) (I ripped the GetEncoderClsid() right out of the GDI+ docs
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytesImageCodecInfo\* pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size); if(size == 0) return -1; // Failure pImageCodecInfo = (ImageCodecInfo\*)(malloc(size)); if(pImageCodecInfo == NULL) return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for(UINT j = 0; j < num; ++j) { if( wcscmp(pImageCodecInfo\[j\].MimeType, format) == 0 ) { \*pClsid = pImageCodecInfo\[j\].Clsid; free(pImageCodecInfo); return j; // Success } } free(pImageCodecInfo); return -1; // Failure
}
...
// Resize an 640x480 image to 320x240 // (I already know this source image is 640x480 - In real life use // SrcBitmap.GetWidth() and SrcBitmap.GetHeight() to get an image's dimensions Gdiplus::Bitmap SrcBitmap(L"D:\\\\Source\\\\Images\\\\sony-cybershot.jpg", FALSE); Gdiplus::Bitmap DstBitmap(320,240,SrcBitmap.GetPixelFormat()); Graphics DstGraphics(&DstBitmap); DstGraphics.DrawImage(&SrcBitmap, 0, 0, 320, 240); CLSID jpgClsid; GetEncoderClsid(L"image/jpeg", &jpgClsid); DstBitmap.Save(L"D:\\\\Source\\\\Images\\\\sony-cybershot\_test.jpg", &jpgClsid, NULL);