Class: Pdfcrowd::ImageToImageClient
- Inherits:
-
Object
- Object
- Pdfcrowd::ImageToImageClient
- Defined in:
- lib/pdfcrowd.rb
Overview
Conversion from one image format to another image format.
Instance Method Summary collapse
- #convertFile(file) ⇒ Object
- #convertFileToFile(file, file_path) ⇒ Object
- #convertFileToStream(file, out_stream) ⇒ Object
- #convertRawData(data) ⇒ Object
- #convertRawDataToFile(data, file_path) ⇒ Object
- #convertRawDataToStream(data, out_stream) ⇒ Object
- #convertStream(in_stream) ⇒ Object
- #convertStreamToFile(in_stream, file_path) ⇒ Object
- #convertStreamToStream(in_stream, out_stream) ⇒ Object
- #convertUrl(url) ⇒ Object
- #convertUrlToFile(url, file_path) ⇒ Object
- #convertUrlToStream(url, out_stream) ⇒ Object
- #getConsumedCreditCount ⇒ Object
- #getDebugLogUrl ⇒ Object
- #getJobId ⇒ Object
- #getOutputSize ⇒ Object
- #getRemainingCreditCount ⇒ Object
- #getVersion ⇒ Object
-
#initialize(user_name, api_key) ⇒ ImageToImageClient
constructor
A new instance of ImageToImageClient.
- #setCanvasBackgroundColor(color) ⇒ Object
- #setCanvasDimensions(width, height) ⇒ Object
- #setCanvasHeight(height) ⇒ Object
- #setCanvasSize(size) ⇒ Object
- #setCanvasWidth(width) ⇒ Object
- #setClientUserAgent(agent) ⇒ Object
- #setConverterVersion(version) ⇒ Object
- #setCropArea(x, y, width, height) ⇒ Object
- #setCropAreaHeight(height) ⇒ Object
- #setCropAreaWidth(width) ⇒ Object
- #setCropAreaX(x) ⇒ Object
- #setCropAreaY(y) ⇒ Object
- #setDebugLog(value) ⇒ Object
- #setDpi(dpi) ⇒ Object
- #setHttpProxy(proxy) ⇒ Object
- #setHttpsProxy(proxy) ⇒ Object
- #setMarginBottom(bottom) ⇒ Object
- #setMarginLeft(left) ⇒ Object
- #setMarginRight(right) ⇒ Object
- #setMargins(top, right, bottom, left) ⇒ Object
- #setMarginTop(top) ⇒ Object
- #setOrientation(orientation) ⇒ Object
- #setOutputFormat(output_format) ⇒ Object
- #setPosition(position) ⇒ Object
- #setPrintCanvasMode(mode) ⇒ Object
- #setProxy(host, port, user_name, password) ⇒ Object
- #setRemoveBorders(value) ⇒ Object
- #setResize(resize) ⇒ Object
- #setRetryCount(count) ⇒ Object
- #setRotate(rotate) ⇒ Object
- #setTag(tag) ⇒ Object
- #setUseHttp(value) ⇒ Object
- #setUserAgent(agent) ⇒ Object
Constructor Details
#initialize(user_name, api_key) ⇒ ImageToImageClient
Returns a new instance of ImageToImageClient.
2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 |
# File 'lib/pdfcrowd.rb', line 2749 def initialize(user_name, api_key) @helper = ConnectionHelper.new(user_name, api_key) @fields = { 'input_format'=>'image', 'output_format'=>'png' } @file_id = 1 @files = {} @raw_data = {} end |
Instance Method Details
#convertFile(file) ⇒ Object
2798 2799 2800 2801 2802 2803 2804 2805 |
# File 'lib/pdfcrowd.rb', line 2798 def convertFile(file) if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(file, "convertFile", "image-to-image", "The file must exist and not be empty.", "convert_file"), 470); end @files['file'] = file @helper.post(@fields, @files, @raw_data) end |
#convertFileToFile(file, file_path) ⇒ Object
2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 |
# File 'lib/pdfcrowd.rb', line 2818 def convertFileToFile(file, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "convertFileToFile::file_path", "image-to-image", "The string must not be empty.", "convert_file_to_file"), 470); end output_file = open(file_path, "wb") begin convertFileToStream(file, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end |
#convertFileToStream(file, out_stream) ⇒ Object
2808 2809 2810 2811 2812 2813 2814 2815 |
# File 'lib/pdfcrowd.rb', line 2808 def convertFileToStream(file, out_stream) if (!(File.file?(file) && !File.zero?(file))) raise Error.new(Pdfcrowd.(file, "convertFileToStream::file", "image-to-image", "The file must exist and not be empty.", "convert_file_to_stream"), 470); end @files['file'] = file @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertRawData(data) ⇒ Object
2835 2836 2837 2838 |
# File 'lib/pdfcrowd.rb', line 2835 def convertRawData(data) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data) end |
#convertRawDataToFile(data, file_path) ⇒ Object
2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 |
# File 'lib/pdfcrowd.rb', line 2847 def convertRawDataToFile(data, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "convertRawDataToFile::file_path", "image-to-image", "The string must not be empty.", "convert_raw_data_to_file"), 470); end output_file = open(file_path, "wb") begin convertRawDataToStream(data, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end |
#convertRawDataToStream(data, out_stream) ⇒ Object
2841 2842 2843 2844 |
# File 'lib/pdfcrowd.rb', line 2841 def convertRawDataToStream(data, out_stream) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertStream(in_stream) ⇒ Object
2864 2865 2866 2867 |
# File 'lib/pdfcrowd.rb', line 2864 def convertStream(in_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data) end |
#convertStreamToFile(in_stream, file_path) ⇒ Object
2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 |
# File 'lib/pdfcrowd.rb', line 2876 def convertStreamToFile(in_stream, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "convertStreamToFile::file_path", "image-to-image", "The string must not be empty.", "convert_stream_to_file"), 470); end output_file = open(file_path, "wb") begin convertStreamToStream(in_stream, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end |
#convertStreamToStream(in_stream, out_stream) ⇒ Object
2870 2871 2872 2873 |
# File 'lib/pdfcrowd.rb', line 2870 def convertStreamToStream(in_stream, out_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertUrl(url) ⇒ Object
2761 2762 2763 2764 2765 2766 2767 2768 |
# File 'lib/pdfcrowd.rb', line 2761 def convertUrl(url) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.(url, "convertUrl", "image-to-image", "Supported protocols are http:// and https://.", "convert_url"), 470); end @fields['url'] = url @helper.post(@fields, @files, @raw_data) end |
#convertUrlToFile(url, file_path) ⇒ Object
2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 |
# File 'lib/pdfcrowd.rb', line 2781 def convertUrlToFile(url, file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "convertUrlToFile::file_path", "image-to-image", "The string must not be empty.", "convert_url_to_file"), 470); end output_file = open(file_path, "wb") begin convertUrlToStream(url, output_file) output_file.close() rescue Error => why output_file.close() FileUtils.rm(file_path) raise end end |
#convertUrlToStream(url, out_stream) ⇒ Object
2771 2772 2773 2774 2775 2776 2777 2778 |
# File 'lib/pdfcrowd.rb', line 2771 def convertUrlToStream(url, out_stream) unless /(?i)^https?:\/\/.*$/.match(url) raise Error.new(Pdfcrowd.(url, "convertUrlToStream::url", "image-to-image", "Supported protocols are http:// and https://.", "convert_url_to_stream"), 470); end @fields['url'] = url @helper.post(@fields, @files, @raw_data, out_stream) end |
#getConsumedCreditCount ⇒ Object
3118 3119 3120 |
# File 'lib/pdfcrowd.rb', line 3118 def getConsumedCreditCount() return @helper.getConsumedCreditCount() end |
#getDebugLogUrl ⇒ Object
3108 3109 3110 |
# File 'lib/pdfcrowd.rb', line 3108 def getDebugLogUrl() return @helper.getDebugLogUrl() end |
#getJobId ⇒ Object
3123 3124 3125 |
# File 'lib/pdfcrowd.rb', line 3123 def getJobId() return @helper.getJobId() end |
#getOutputSize ⇒ Object
3128 3129 3130 |
# File 'lib/pdfcrowd.rb', line 3128 def getOutputSize() return @helper.getOutputSize() end |
#getRemainingCreditCount ⇒ Object
3113 3114 3115 |
# File 'lib/pdfcrowd.rb', line 3113 def getRemainingCreditCount() return @helper.getRemainingCreditCount() end |
#getVersion ⇒ Object
3133 3134 3135 |
# File 'lib/pdfcrowd.rb', line 3133 def getVersion() return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion() end |
#setCanvasBackgroundColor(color) ⇒ Object
3086 3087 3088 3089 3090 3091 3092 3093 |
# File 'lib/pdfcrowd.rb', line 3086 def setCanvasBackgroundColor(color) unless /^[0-9a-fA-F]{6,8}$/.match(color) raise Error.new(Pdfcrowd.(color, "setCanvasBackgroundColor", "image-to-image", "The value must be in RRGGBB or RRGGBBAA hexadecimal format.", "set_canvas_background_color"), 470); end @fields['canvas_background_color'] = color self end |
#setCanvasDimensions(width, height) ⇒ Object
3000 3001 3002 3003 3004 |
# File 'lib/pdfcrowd.rb', line 3000 def setCanvasDimensions(width, height) setCanvasWidth(width) setCanvasHeight(height) self end |
#setCanvasHeight(height) ⇒ Object
2990 2991 2992 2993 2994 2995 2996 2997 |
# File 'lib/pdfcrowd.rb', line 2990 def setCanvasHeight(height) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(height) raise Error.new(Pdfcrowd.(height, "setCanvasHeight", "image-to-image", "The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.", "set_canvas_height"), 470); end @fields['canvas_height'] = height self end |
#setCanvasSize(size) ⇒ Object
2970 2971 2972 2973 2974 2975 2976 2977 |
# File 'lib/pdfcrowd.rb', line 2970 def setCanvasSize(size) unless /(?i)^(A0|A1|A2|A3|A4|A5|A6|Letter)$/.match(size) raise Error.new(Pdfcrowd.(size, "setCanvasSize", "image-to-image", "Allowed values are A0, A1, A2, A3, A4, A5, A6, Letter.", "set_canvas_size"), 470); end @fields['canvas_size'] = size self end |
#setCanvasWidth(width) ⇒ Object
2980 2981 2982 2983 2984 2985 2986 2987 |
# File 'lib/pdfcrowd.rb', line 2980 def setCanvasWidth(width) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(width) raise Error.new(Pdfcrowd.(width, "setCanvasWidth", "image-to-image", "The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.", "set_canvas_width"), 470); end @fields['canvas_width'] = width self end |
#setClientUserAgent(agent) ⇒ Object
3180 3181 3182 3183 |
# File 'lib/pdfcrowd.rb', line 3180 def setClientUserAgent(agent) @helper.setUserAgent(agent) self end |
#setConverterVersion(version) ⇒ Object
3164 3165 3166 3167 3168 3169 3170 3171 |
# File 'lib/pdfcrowd.rb', line 3164 def setConverterVersion(version) unless /(?i)^(24.04|20.10|18.10|latest)$/.match(version) raise Error.new(Pdfcrowd.(version, "setConverterVersion", "image-to-image", "Allowed values are 24.04, 20.10, 18.10, latest.", "set_converter_version"), 470); end @helper.setConverterVersion(version) self end |
#setCropArea(x, y, width, height) ⇒ Object
2955 2956 2957 2958 2959 2960 2961 |
# File 'lib/pdfcrowd.rb', line 2955 def setCropArea(x, y, width, height) setCropAreaX(x) setCropAreaY(y) setCropAreaWidth(width) setCropAreaHeight(height) self end |
#setCropAreaHeight(height) ⇒ Object
2945 2946 2947 2948 2949 2950 2951 2952 |
# File 'lib/pdfcrowd.rb', line 2945 def setCropAreaHeight(height) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(height) raise Error.new(Pdfcrowd.(height, "setCropAreaHeight", "image-to-image", "The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.", "set_crop_area_height"), 470); end @fields['crop_area_height'] = height self end |
#setCropAreaWidth(width) ⇒ Object
2935 2936 2937 2938 2939 2940 2941 2942 |
# File 'lib/pdfcrowd.rb', line 2935 def setCropAreaWidth(width) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(width) raise Error.new(Pdfcrowd.(width, "setCropAreaWidth", "image-to-image", "The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.", "set_crop_area_width"), 470); end @fields['crop_area_width'] = width self end |
#setCropAreaX(x) ⇒ Object
2915 2916 2917 2918 2919 2920 2921 2922 |
# File 'lib/pdfcrowd.rb', line 2915 def setCropAreaX(x) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(x) raise Error.new(Pdfcrowd.(x, "setCropAreaX", "image-to-image", "The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.", "set_crop_area_x"), 470); end @fields['crop_area_x'] = x self end |
#setCropAreaY(y) ⇒ Object
2925 2926 2927 2928 2929 2930 2931 2932 |
# File 'lib/pdfcrowd.rb', line 2925 def setCropAreaY(y) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(y) raise Error.new(Pdfcrowd.(y, "setCropAreaY", "image-to-image", "The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.", "set_crop_area_y"), 470); end @fields['crop_area_y'] = y self end |
#setDebugLog(value) ⇒ Object
3102 3103 3104 3105 |
# File 'lib/pdfcrowd.rb', line 3102 def setDebugLog(value) @fields['debug_log'] = value self end |
#setDpi(dpi) ⇒ Object
3096 3097 3098 3099 |
# File 'lib/pdfcrowd.rb', line 3096 def setDpi(dpi) @fields['dpi'] = dpi self end |
#setHttpProxy(proxy) ⇒ Object
3144 3145 3146 3147 3148 3149 3150 3151 |
# File 'lib/pdfcrowd.rb', line 3144 def setHttpProxy(proxy) unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy) raise Error.new(Pdfcrowd.(proxy, "setHttpProxy", "image-to-image", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_http_proxy"), 470); end @fields['http_proxy'] = proxy self end |
#setHttpsProxy(proxy) ⇒ Object
3154 3155 3156 3157 3158 3159 3160 3161 |
# File 'lib/pdfcrowd.rb', line 3154 def setHttpsProxy(proxy) unless /(?i)^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z0-9]{1,}:\d+$/.match(proxy) raise Error.new(Pdfcrowd.(proxy, "setHttpsProxy", "image-to-image", "The value must have format DOMAIN_OR_IP_ADDRESS:PORT.", "set_https_proxy"), 470); end @fields['https_proxy'] = proxy self end |
#setMarginBottom(bottom) ⇒ Object
3057 3058 3059 3060 3061 3062 3063 3064 |
# File 'lib/pdfcrowd.rb', line 3057 def setMarginBottom(bottom) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(bottom) raise Error.new(Pdfcrowd.(bottom, "setMarginBottom", "image-to-image", "The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.", "set_margin_bottom"), 470); end @fields['margin_bottom'] = bottom self end |
#setMarginLeft(left) ⇒ Object
3067 3068 3069 3070 3071 3072 3073 3074 |
# File 'lib/pdfcrowd.rb', line 3067 def setMarginLeft(left) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(left) raise Error.new(Pdfcrowd.(left, "setMarginLeft", "image-to-image", "The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.", "set_margin_left"), 470); end @fields['margin_left'] = left self end |
#setMarginRight(right) ⇒ Object
3047 3048 3049 3050 3051 3052 3053 3054 |
# File 'lib/pdfcrowd.rb', line 3047 def setMarginRight(right) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(right) raise Error.new(Pdfcrowd.(right, "setMarginRight", "image-to-image", "The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.", "set_margin_right"), 470); end @fields['margin_right'] = right self end |
#setMargins(top, right, bottom, left) ⇒ Object
3077 3078 3079 3080 3081 3082 3083 |
# File 'lib/pdfcrowd.rb', line 3077 def setMargins(top, right, bottom, left) setMarginTop(top) setMarginRight(right) setMarginBottom(bottom) setMarginLeft(left) self end |
#setMarginTop(top) ⇒ Object
3037 3038 3039 3040 3041 3042 3043 3044 |
# File 'lib/pdfcrowd.rb', line 3037 def setMarginTop(top) unless /(?i)^0$|^[0-9]*\.?[0-9]+(pt|px|mm|cm|in)$/.match(top) raise Error.new(Pdfcrowd.(top, "setMarginTop", "image-to-image", "The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.", "set_margin_top"), 470); end @fields['margin_top'] = top self end |
#setOrientation(orientation) ⇒ Object
3007 3008 3009 3010 3011 3012 3013 3014 |
# File 'lib/pdfcrowd.rb', line 3007 def setOrientation(orientation) unless /(?i)^(landscape|portrait)$/.match(orientation) raise Error.new(Pdfcrowd.(orientation, "setOrientation", "image-to-image", "Allowed values are landscape, portrait.", "set_orientation"), 470); end @fields['orientation'] = orientation self end |
#setOutputFormat(output_format) ⇒ Object
2893 2894 2895 2896 2897 2898 2899 2900 |
# File 'lib/pdfcrowd.rb', line 2893 def setOutputFormat(output_format) unless /(?i)^(png|jpg|gif|tiff|bmp|ico|ppm|pgm|pbm|pnm|psb|pct|ras|tga|sgi|sun|webp)$/.match(output_format) raise Error.new(Pdfcrowd.(output_format, "setOutputFormat", "image-to-image", "Allowed values are png, jpg, gif, tiff, bmp, ico, ppm, pgm, pbm, pnm, psb, pct, ras, tga, sgi, sun, webp.", "set_output_format"), 470); end @fields['output_format'] = output_format self end |
#setPosition(position) ⇒ Object
3017 3018 3019 3020 3021 3022 3023 3024 |
# File 'lib/pdfcrowd.rb', line 3017 def setPosition(position) unless /(?i)^(center|top|bottom|left|right|top-left|top-right|bottom-left|bottom-right)$/.match(position) raise Error.new(Pdfcrowd.(position, "setPosition", "image-to-image", "Allowed values are center, top, bottom, left, right, top-left, top-right, bottom-left, bottom-right.", "set_position"), 470); end @fields['position'] = position self end |
#setPrintCanvasMode(mode) ⇒ Object
3027 3028 3029 3030 3031 3032 3033 3034 |
# File 'lib/pdfcrowd.rb', line 3027 def setPrintCanvasMode(mode) unless /(?i)^(default|fit|stretch)$/.match(mode) raise Error.new(Pdfcrowd.(mode, "setPrintCanvasMode", "image-to-image", "Allowed values are default, fit, stretch.", "set_print_canvas_mode"), 470); end @fields['print_canvas_mode'] = mode self end |
#setProxy(host, port, user_name, password) ⇒ Object
3192 3193 3194 3195 |
# File 'lib/pdfcrowd.rb', line 3192 def setProxy(host, port, user_name, password) @helper.setProxy(host, port, user_name, password) self end |
#setRemoveBorders(value) ⇒ Object
2964 2965 2966 2967 |
# File 'lib/pdfcrowd.rb', line 2964 def setRemoveBorders(value) @fields['remove_borders'] = value self end |
#setResize(resize) ⇒ Object
2903 2904 2905 2906 |
# File 'lib/pdfcrowd.rb', line 2903 def setResize(resize) @fields['resize'] = resize self end |
#setRetryCount(count) ⇒ Object
3198 3199 3200 3201 |
# File 'lib/pdfcrowd.rb', line 3198 def setRetryCount(count) @helper.setRetryCount(count) self end |
#setRotate(rotate) ⇒ Object
2909 2910 2911 2912 |
# File 'lib/pdfcrowd.rb', line 2909 def setRotate(rotate) @fields['rotate'] = rotate self end |
#setTag(tag) ⇒ Object
3138 3139 3140 3141 |
# File 'lib/pdfcrowd.rb', line 3138 def setTag(tag) @fields['tag'] = tag self end |
#setUseHttp(value) ⇒ Object
3174 3175 3176 3177 |
# File 'lib/pdfcrowd.rb', line 3174 def setUseHttp(value) @helper.setUseHttp(value) self end |
#setUserAgent(agent) ⇒ Object
3186 3187 3188 3189 |
# File 'lib/pdfcrowd.rb', line 3186 def setUserAgent(agent) @helper.setUserAgent(agent) self end |