added: a new winix function: imgcrop
for cropping images (and thumbnails) www.domain.com/dir/file.jpg/imgcrop -- crop an image www.domain.com/dir/file.jpg/imgcrop/thumb -- crop an image's thumbnail www.domain.com/dir/file.jpg/imgcrop/newthumb -- crop and create a new thumbnail (from an original image) www.domain.com/dir/imgcrop -- show images' list with above options added: to Image class: some methods for cropping git-svn-id: svn://ttmath.org/publicrep/winix/trunk@919 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
101
functions/imgcrop.cpp
Executable file
101
functions/imgcrop.cpp
Executable file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2013, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "imgcrop.h"
|
||||
#include "functions.h"
|
||||
|
||||
|
||||
|
||||
namespace Fun
|
||||
{
|
||||
|
||||
ImgCrop::ImgCrop()
|
||||
{
|
||||
fun.url = L"imgcrop";
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ImgCrop::HasAccess()
|
||||
{
|
||||
if( cur->request->is_item )
|
||||
return system->HasWriteAccess(cur->request->item);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ImgCrop::GetDirContent()
|
||||
{
|
||||
iq.sel_content = false;
|
||||
iq.WhereParentId(cur->request->dir_tab.back()->id);
|
||||
db->GetItems(cur->request->item_tab, iq);
|
||||
system->CheckWriteAccessToItems(cur->request->item_tab);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ImgCrop::MakePost()
|
||||
{
|
||||
int xoffset = int(Tod(cur->request->PostVar(L"cropxtop")) + 0.5);
|
||||
int yoffset = int(Tod(cur->request->PostVar(L"cropytop")) + 0.5);
|
||||
int width = int(Tod(cur->request->PostVar(L"cropwidth")) + 0.5);
|
||||
int height = int(Tod(cur->request->PostVar(L"cropheight")) + 0.5);
|
||||
|
||||
SetMinMax(xoffset, 0, 30000);
|
||||
SetMinMax(yoffset, 0, 30000);
|
||||
SetMinMax(width, 1, 30000);
|
||||
SetMinMax(height, 1, 30000);
|
||||
|
||||
Item & item = cur->request->item;
|
||||
|
||||
if( cur->request->is_item && item.type == Item::file && item.file_type == WINIX_ITEM_FILETYPE_IMAGE )
|
||||
{
|
||||
if( system->HasWriteAccess(item) )
|
||||
{
|
||||
// !! IMPROVE ME add info about modification (Item::modify_time)
|
||||
if( cur->request->IsParam(L"thumb") )
|
||||
{
|
||||
Image::Scale scale = system->image.GetThumbScale(item.parent_id);
|
||||
system->image.CropThumb(item.id, xoffset, yoffset, width, height, scale.quality);
|
||||
}
|
||||
else
|
||||
if( cur->request->IsParam(L"newthumb") )
|
||||
{
|
||||
Image::Scale scale = system->image.GetThumbScale(item.parent_id);
|
||||
system->image.CropNewThumb(item.id, xoffset, yoffset, width, height, scale.cx, scale.cy,
|
||||
scale.aspect_mode, scale.quality);
|
||||
}
|
||||
else
|
||||
{
|
||||
Image::Scale scale = system->image.GetImageScale(item.parent_id);
|
||||
system->image.Crop(item.id, xoffset, yoffset, width, height, scale.quality);
|
||||
}
|
||||
|
||||
// !! IMPROVE ME redirect me somewhere else
|
||||
system->RedirectToLastItem();
|
||||
}
|
||||
else
|
||||
{
|
||||
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ImgCrop::MakeGet()
|
||||
{
|
||||
if( !cur->request->is_item )
|
||||
GetDirContent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
Reference in New Issue
Block a user