Esempio n. 1
0
        public virtual XVar create_scaled_image(dynamic _param_file_path, dynamic _param_uploadDir, dynamic _param_new_file_name, dynamic _param_options, dynamic file, dynamic _param_isThumbnail, dynamic _param_uploadDirRelative, dynamic _param_uploadedFile)
        {
            #region pass-by-value parameters
            dynamic file_path         = XVar.Clone(_param_file_path);
            dynamic uploadDir         = XVar.Clone(_param_uploadDir);
            dynamic new_file_name     = XVar.Clone(_param_new_file_name);
            dynamic options           = XVar.Clone(_param_options);
            dynamic isThumbnail       = XVar.Clone(_param_isThumbnail);
            dynamic uploadDirRelative = XVar.Clone(_param_uploadDirRelative);
            dynamic uploadedFile      = XVar.Clone(_param_uploadedFile);
            #endregion

            dynamic img_height = null, img_size = XVar.Array(), img_width = null, new_file_path = null, new_height = null, new_width = null, scale = null, success = null;
            img_size      = XVar.Clone(MVCFunctions.runner_getimagesize((XVar)(file_path), (XVar)(uploadedFile)));
            img_width     = XVar.Clone(img_size[0]);
            img_height    = XVar.Clone(img_size[1]);
            new_file_path = XVar.Clone(MVCFunctions.Concat(uploadDir, new_file_name));
            if ((XVar)(!(XVar)(img_width)) || (XVar)(!(XVar)(img_height)))
            {
                MVCFunctions.unlink((XVar)(new_file_path));
                return(false);
            }
            scale = XVar.Clone(MVCFunctions.min((XVar)(options["max_width"] / img_width), (XVar)(options["max_height"] / img_height)));
            if (1 <= scale)
            {
                if (!XVar.Equals(XVar.Pack(file_path), XVar.Pack(new_file_path)))
                {
                    dynamic result = null;
                    result = XVar.Clone(MVCFunctions.copy((XVar)(file_path), (XVar)(new_file_path)));
                    if ((XVar)(result) && (XVar)(isThumbnail))
                    {
                        file.InitAndSetArrayItem(MVCFunctions.Concat(uploadDirRelative, new_file_name), "thumbnail");
                        file.InitAndSetArrayItem(MVCFunctions.filesize((XVar)(file_path)), "thumbnail_size");
                        file.InitAndSetArrayItem(file["type"], "thumbnail_type");
                    }
                    return(result);
                }
                return(false);
            }
            new_width  = XVar.Clone(img_width * scale);
            new_height = XVar.Clone(img_height * scale);
            success    = XVar.Clone(MVCFunctions.imageCreateThumb((XVar)(new_width), (XVar)(new_height), (XVar)(img_width), (XVar)(img_height), (XVar)(file_path), (XVar)(options), (XVar)(new_file_path), (XVar)(uploadedFile)));
            if (XVar.Pack(success))
            {
                if (XVar.Pack(isThumbnail))
                {
                    file.InitAndSetArrayItem(MVCFunctions.Concat(uploadDirRelative, new_file_name), "thumbnail");
                    file.InitAndSetArrayItem(MVCFunctions.filesize((XVar)(new_file_path)), "thumbnail_size");
                    file.InitAndSetArrayItem(file["type"], "thumbnail_type");
                }
                else
                {
                    file.InitAndSetArrayItem(new_file_name, "name");
                    file.InitAndSetArrayItem(MVCFunctions.filesize((XVar)(new_file_path)), "size");
                }
            }
            return(success);
        }