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.
2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 |
# File 'lib/pdfcrowd.rb', line 2722 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
2771 2772 2773 2774 2775 2776 2777 2778 |
# File 'lib/pdfcrowd.rb', line 2771 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
2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 |
# File 'lib/pdfcrowd.rb', line 2791 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
2781 2782 2783 2784 2785 2786 2787 2788 |
# File 'lib/pdfcrowd.rb', line 2781 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
2808 2809 2810 2811 |
# File 'lib/pdfcrowd.rb', line 2808 def convertRawData(data) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data) end |
#convertRawDataToFile(data, file_path) ⇒ Object
2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 |
# File 'lib/pdfcrowd.rb', line 2820 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
2814 2815 2816 2817 |
# File 'lib/pdfcrowd.rb', line 2814 def convertRawDataToStream(data, out_stream) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertStream(in_stream) ⇒ Object
2837 2838 2839 2840 |
# File 'lib/pdfcrowd.rb', line 2837 def convertStream(in_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data) end |
#convertStreamToFile(in_stream, file_path) ⇒ Object
2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 |
# File 'lib/pdfcrowd.rb', line 2849 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
2843 2844 2845 2846 |
# File 'lib/pdfcrowd.rb', line 2843 def convertStreamToStream(in_stream, out_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertUrl(url) ⇒ Object
2734 2735 2736 2737 2738 2739 2740 2741 |
# File 'lib/pdfcrowd.rb', line 2734 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
2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 |
# File 'lib/pdfcrowd.rb', line 2754 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
2744 2745 2746 2747 2748 2749 2750 2751 |
# File 'lib/pdfcrowd.rb', line 2744 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
3091 3092 3093 |
# File 'lib/pdfcrowd.rb', line 3091 def getConsumedCreditCount() return @helper.getConsumedCreditCount() end |
#getDebugLogUrl ⇒ Object
3081 3082 3083 |
# File 'lib/pdfcrowd.rb', line 3081 def getDebugLogUrl() return @helper.getDebugLogUrl() end |
#getJobId ⇒ Object
3096 3097 3098 |
# File 'lib/pdfcrowd.rb', line 3096 def getJobId() return @helper.getJobId() end |
#getOutputSize ⇒ Object
3101 3102 3103 |
# File 'lib/pdfcrowd.rb', line 3101 def getOutputSize() return @helper.getOutputSize() end |
#getRemainingCreditCount ⇒ Object
3086 3087 3088 |
# File 'lib/pdfcrowd.rb', line 3086 def getRemainingCreditCount() return @helper.getRemainingCreditCount() end |
#getVersion ⇒ Object
3106 3107 3108 |
# File 'lib/pdfcrowd.rb', line 3106 def getVersion() return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion() end |
#setCanvasBackgroundColor(color) ⇒ Object
3059 3060 3061 3062 3063 3064 3065 3066 |
# File 'lib/pdfcrowd.rb', line 3059 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
2973 2974 2975 2976 2977 |
# File 'lib/pdfcrowd.rb', line 2973 def setCanvasDimensions(width, height) setCanvasWidth(width) setCanvasHeight(height) self end |
#setCanvasHeight(height) ⇒ Object
2963 2964 2965 2966 2967 2968 2969 2970 |
# File 'lib/pdfcrowd.rb', line 2963 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
2943 2944 2945 2946 2947 2948 2949 2950 |
# File 'lib/pdfcrowd.rb', line 2943 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
2953 2954 2955 2956 2957 2958 2959 2960 |
# File 'lib/pdfcrowd.rb', line 2953 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
3153 3154 3155 3156 |
# File 'lib/pdfcrowd.rb', line 3153 def setClientUserAgent(agent) @helper.setUserAgent(agent) self end |
#setConverterVersion(version) ⇒ Object
3137 3138 3139 3140 3141 3142 3143 3144 |
# File 'lib/pdfcrowd.rb', line 3137 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
2928 2929 2930 2931 2932 2933 2934 |
# File 'lib/pdfcrowd.rb', line 2928 def setCropArea(x, y, width, height) setCropAreaX(x) setCropAreaY(y) setCropAreaWidth(width) setCropAreaHeight(height) self end |
#setCropAreaHeight(height) ⇒ Object
2918 2919 2920 2921 2922 2923 2924 2925 |
# File 'lib/pdfcrowd.rb', line 2918 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
2908 2909 2910 2911 2912 2913 2914 2915 |
# File 'lib/pdfcrowd.rb', line 2908 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
2888 2889 2890 2891 2892 2893 2894 2895 |
# File 'lib/pdfcrowd.rb', line 2888 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
2898 2899 2900 2901 2902 2903 2904 2905 |
# File 'lib/pdfcrowd.rb', line 2898 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
3075 3076 3077 3078 |
# File 'lib/pdfcrowd.rb', line 3075 def setDebugLog(value) @fields['debug_log'] = value self end |
#setDpi(dpi) ⇒ Object
3069 3070 3071 3072 |
# File 'lib/pdfcrowd.rb', line 3069 def setDpi(dpi) @fields['dpi'] = dpi self end |
#setHttpProxy(proxy) ⇒ Object
3117 3118 3119 3120 3121 3122 3123 3124 |
# File 'lib/pdfcrowd.rb', line 3117 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
3127 3128 3129 3130 3131 3132 3133 3134 |
# File 'lib/pdfcrowd.rb', line 3127 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
3030 3031 3032 3033 3034 3035 3036 3037 |
# File 'lib/pdfcrowd.rb', line 3030 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
3040 3041 3042 3043 3044 3045 3046 3047 |
# File 'lib/pdfcrowd.rb', line 3040 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
3020 3021 3022 3023 3024 3025 3026 3027 |
# File 'lib/pdfcrowd.rb', line 3020 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
3050 3051 3052 3053 3054 3055 3056 |
# File 'lib/pdfcrowd.rb', line 3050 def setMargins(top, right, bottom, left) setMarginTop(top) setMarginRight(right) setMarginBottom(bottom) setMarginLeft(left) self end |
#setMarginTop(top) ⇒ Object
3010 3011 3012 3013 3014 3015 3016 3017 |
# File 'lib/pdfcrowd.rb', line 3010 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
2980 2981 2982 2983 2984 2985 2986 2987 |
# File 'lib/pdfcrowd.rb', line 2980 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
2866 2867 2868 2869 2870 2871 2872 2873 |
# File 'lib/pdfcrowd.rb', line 2866 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
2990 2991 2992 2993 2994 2995 2996 2997 |
# File 'lib/pdfcrowd.rb', line 2990 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
3000 3001 3002 3003 3004 3005 3006 3007 |
# File 'lib/pdfcrowd.rb', line 3000 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
3165 3166 3167 3168 |
# File 'lib/pdfcrowd.rb', line 3165 def setProxy(host, port, user_name, password) @helper.setProxy(host, port, user_name, password) self end |
#setRemoveBorders(value) ⇒ Object
2937 2938 2939 2940 |
# File 'lib/pdfcrowd.rb', line 2937 def setRemoveBorders(value) @fields['remove_borders'] = value self end |
#setResize(resize) ⇒ Object
2876 2877 2878 2879 |
# File 'lib/pdfcrowd.rb', line 2876 def setResize(resize) @fields['resize'] = resize self end |
#setRetryCount(count) ⇒ Object
3171 3172 3173 3174 |
# File 'lib/pdfcrowd.rb', line 3171 def setRetryCount(count) @helper.setRetryCount(count) self end |
#setRotate(rotate) ⇒ Object
2882 2883 2884 2885 |
# File 'lib/pdfcrowd.rb', line 2882 def setRotate(rotate) @fields['rotate'] = rotate self end |
#setTag(tag) ⇒ Object
3111 3112 3113 3114 |
# File 'lib/pdfcrowd.rb', line 3111 def setTag(tag) @fields['tag'] = tag self end |
#setUseHttp(value) ⇒ Object
3147 3148 3149 3150 |
# File 'lib/pdfcrowd.rb', line 3147 def setUseHttp(value) @helper.setUseHttp(value) self end |
#setUserAgent(agent) ⇒ Object
3159 3160 3161 3162 |
# File 'lib/pdfcrowd.rb', line 3159 def setUserAgent(agent) @helper.setUserAgent(agent) self end |