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:
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
o = adduser.o cat.o chmod.o chown.o ckeditor.o cp.o default.o download.o emacs.o env.o functionbase.o functionparser.o functions.o ipban.o last.o ln.o locale.o login.o logout.o ls.o man.o meta.o mkdir.o mount.o mv.o nicedit.o node.o passwd.o priv.o privchanger.o pw.o reload.o rm.o rmuser.o run.o sort.o specialdefault.o stat.o subject.o template.o timezone.o tinymce.o uname.o upload.o uptime.o vim.o who.o
|
||||
o = adduser.o cat.o chmod.o chown.o ckeditor.o cp.o default.o download.o emacs.o env.o functionbase.o functionparser.o functions.o imgcrop.o ipban.o last.o ln.o locale.o login.o logout.o ls.o man.o meta.o mkdir.o mount.o mv.o nicedit.o node.o passwd.o priv.o privchanger.o pw.o reload.o rm.o rmuser.o run.o sort.o specialdefault.o stat.o subject.o template.o timezone.o tinymce.o uname.o upload.o uptime.o vim.o who.o
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010-2012, Tomasz Sowa
|
||||
* Copyright (c) 2010-2013, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -192,6 +192,7 @@ void Functions::CreateFunctions()
|
||||
Add(fun_download);
|
||||
Add(fun_emacs);
|
||||
Add(fun_env);
|
||||
Add(fun_imgcrop);
|
||||
Add(fun_last);
|
||||
Add(fun_locale);
|
||||
Add(fun_login);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010-2012, Tomasz Sowa
|
||||
* Copyright (c) 2010-2013, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "download.h"
|
||||
#include "emacs.h"
|
||||
#include "env.h"
|
||||
#include "imgcrop.h"
|
||||
#include "last.h"
|
||||
#include "locale.h"
|
||||
#include "login.h"
|
||||
@@ -77,6 +78,7 @@ public:
|
||||
Fun::Download fun_download;
|
||||
Fun::Emacs fun_emacs;
|
||||
Fun::Env fun_env;
|
||||
Fun::ImgCrop fun_imgcrop;
|
||||
Fun::Last fun_last;
|
||||
Fun::Locale fun_locale;
|
||||
Fun::Login fun_login;
|
||||
|
||||
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
|
||||
42
functions/imgcrop.h
Executable file
42
functions/imgcrop.h
Executable file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2013, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_functions_imgcrop
|
||||
#define headerfile_winix_functions_imgcrop
|
||||
|
||||
#include "functionbase.h"
|
||||
|
||||
|
||||
|
||||
namespace Fun
|
||||
{
|
||||
|
||||
|
||||
class ImgCrop : public FunctionBase
|
||||
{
|
||||
public:
|
||||
|
||||
ImgCrop();
|
||||
|
||||
bool HasAccess();
|
||||
void MakeGet();
|
||||
void MakePost();
|
||||
|
||||
private:
|
||||
|
||||
DbItemQuery iq;
|
||||
|
||||
void GetDirContent();
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2012, Tomasz Sowa
|
||||
* Copyright (c) 2008-2013, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -89,68 +89,16 @@ bool Upload::UploadSaveStaticFile(const Item & item, const std::wstring & tmp_fi
|
||||
|
||||
void Upload::ResizeImage(Item & item)
|
||||
{
|
||||
::Mount * m = system->mounts.CalcMount(item.parent_id);
|
||||
size_t cx = config->image_cx;
|
||||
size_t cy = config->image_cy;
|
||||
int mode = config->image_mode;
|
||||
int quality = config->image_quality;
|
||||
|
||||
// reading width and height from the mount point (if exists)
|
||||
int index = system->mounts.MountParImageSize();
|
||||
|
||||
if( m && m->param[index].defined && m->param[index].arg.size() == 2 )
|
||||
{
|
||||
cx = Tol(m->param[index].arg[0]);
|
||||
cy = Tol(m->param[index].arg[1]);
|
||||
}
|
||||
|
||||
// reading image mode from the mount point (if exists)
|
||||
index = system->mounts.MountParImageMode();
|
||||
|
||||
if( m && m->param[index].defined && m->param[index].arg.size() == 1 )
|
||||
mode = Toi(m->param[index].arg[0]);
|
||||
|
||||
// reading image quality from the mount point (if exists)
|
||||
index = system->mounts.MountParImageQuality();
|
||||
|
||||
if( m && m->param[index].defined && m->param[index].arg.size() == 1 )
|
||||
quality = Toi(m->param[index].arg[0]);
|
||||
|
||||
system->image.Resize(item, cx, cy, mode, quality);
|
||||
Image::Scale scale = system->image.GetImageScale(item.parent_id);
|
||||
system->image.Resize(item.id, scale.cx, scale.cy, scale.aspect_mode, scale.quality);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Upload::CreateThumb(Item & item)
|
||||
{
|
||||
::Mount * m = system->mounts.CalcMount(item.parent_id);
|
||||
size_t cx = config->thumb_cx;
|
||||
size_t cy = config->thumb_cy;
|
||||
int mode = config->thumb_mode;
|
||||
int quality = config->thumb_quality;
|
||||
|
||||
// reading width and height from the mount point (if exists)
|
||||
int index = system->mounts.MountParThumbSize();
|
||||
|
||||
if( m && m->param[index].defined && m->param[index].arg.size() == 2 )
|
||||
{
|
||||
cx = Tol(m->param[index].arg[0]);
|
||||
cy = Tol(m->param[index].arg[1]);
|
||||
}
|
||||
|
||||
// reading thumb mode from the mount point (if exists)
|
||||
index = system->mounts.MountParThumbMode();
|
||||
|
||||
if( m && m->param[index].defined && m->param[index].arg.size() == 1 )
|
||||
mode = Toi(m->param[index].arg[0]);
|
||||
|
||||
// reading image quality from the mount point (if exists)
|
||||
index = system->mounts.MountParThumbQuality();
|
||||
|
||||
if( m && m->param[index].defined && m->param[index].arg.size() == 1 )
|
||||
quality = Toi(m->param[index].arg[0]);
|
||||
|
||||
system->image.CreateThumb(item, cx, cy, mode, quality);
|
||||
Image::Scale scale = system->image.GetThumbScale(item.parent_id);
|
||||
system->image.CreateThumb(item.id, scale.cx, scale.cy, scale.aspect_mode, scale.quality);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user