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.
2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 |
# File 'lib/pdfcrowd.rb', line 2702 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
2751 2752 2753 2754 2755 2756 2757 2758 |
# File 'lib/pdfcrowd.rb', line 2751 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
2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 |
# File 'lib/pdfcrowd.rb', line 2771 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
2761 2762 2763 2764 2765 2766 2767 2768 |
# File 'lib/pdfcrowd.rb', line 2761 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
2788 2789 2790 2791 |
# File 'lib/pdfcrowd.rb', line 2788 def convertRawData(data) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data) end |
#convertRawDataToFile(data, file_path) ⇒ Object
2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 |
# File 'lib/pdfcrowd.rb', line 2800 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
2794 2795 2796 2797 |
# File 'lib/pdfcrowd.rb', line 2794 def convertRawDataToStream(data, out_stream) @raw_data['file'] = data @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertStream(in_stream) ⇒ Object
2817 2818 2819 2820 |
# File 'lib/pdfcrowd.rb', line 2817 def convertStream(in_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data) end |
#convertStreamToFile(in_stream, file_path) ⇒ Object
2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 |
# File 'lib/pdfcrowd.rb', line 2829 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
2823 2824 2825 2826 |
# File 'lib/pdfcrowd.rb', line 2823 def convertStreamToStream(in_stream, out_stream) @raw_data['stream'] = in_stream.read @helper.post(@fields, @files, @raw_data, out_stream) end |
#convertUrl(url) ⇒ Object
2714 2715 2716 2717 2718 2719 2720 2721 |
# File 'lib/pdfcrowd.rb', line 2714 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
2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 |
# File 'lib/pdfcrowd.rb', line 2734 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
2724 2725 2726 2727 2728 2729 2730 2731 |
# File 'lib/pdfcrowd.rb', line 2724 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
3071 3072 3073 |
# File 'lib/pdfcrowd.rb', line 3071 def getConsumedCreditCount() return @helper.getConsumedCreditCount() end |
#getDebugLogUrl ⇒ Object
3061 3062 3063 |
# File 'lib/pdfcrowd.rb', line 3061 def getDebugLogUrl() return @helper.getDebugLogUrl() end |
#getJobId ⇒ Object
3076 3077 3078 |
# File 'lib/pdfcrowd.rb', line 3076 def getJobId() return @helper.getJobId() end |
#getOutputSize ⇒ Object
3081 3082 3083 |
# File 'lib/pdfcrowd.rb', line 3081 def getOutputSize() return @helper.getOutputSize() end |
#getRemainingCreditCount ⇒ Object
3066 3067 3068 |
# File 'lib/pdfcrowd.rb', line 3066 def getRemainingCreditCount() return @helper.getRemainingCreditCount() end |
#getVersion ⇒ Object
3086 3087 3088 |
# File 'lib/pdfcrowd.rb', line 3086 def getVersion() return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion() end |
#setCanvasBackgroundColor(color) ⇒ Object
3039 3040 3041 3042 3043 3044 3045 3046 |
# File 'lib/pdfcrowd.rb', line 3039 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
2953 2954 2955 2956 2957 |
# File 'lib/pdfcrowd.rb', line 2953 def setCanvasDimensions(width, height) setCanvasWidth(width) setCanvasHeight(height) self end |
#setCanvasHeight(height) ⇒ Object
2943 2944 2945 2946 2947 2948 2949 2950 |
# File 'lib/pdfcrowd.rb', line 2943 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
2923 2924 2925 2926 2927 2928 2929 2930 |
# File 'lib/pdfcrowd.rb', line 2923 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
2933 2934 2935 2936 2937 2938 2939 2940 |
# File 'lib/pdfcrowd.rb', line 2933 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
3133 3134 3135 3136 |
# File 'lib/pdfcrowd.rb', line 3133 def setClientUserAgent(agent) @helper.setUserAgent(agent) self end |
#setConverterVersion(version) ⇒ Object
3117 3118 3119 3120 3121 3122 3123 3124 |
# File 'lib/pdfcrowd.rb', line 3117 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
2908 2909 2910 2911 2912 2913 2914 |
# File 'lib/pdfcrowd.rb', line 2908 def setCropArea(x, y, width, height) setCropAreaX(x) setCropAreaY(y) setCropAreaWidth(width) setCropAreaHeight(height) self end |
#setCropAreaHeight(height) ⇒ Object
2898 2899 2900 2901 2902 2903 2904 2905 |
# File 'lib/pdfcrowd.rb', line 2898 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
2888 2889 2890 2891 2892 2893 2894 2895 |
# File 'lib/pdfcrowd.rb', line 2888 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
2868 2869 2870 2871 2872 2873 2874 2875 |
# File 'lib/pdfcrowd.rb', line 2868 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
2878 2879 2880 2881 2882 2883 2884 2885 |
# File 'lib/pdfcrowd.rb', line 2878 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
3055 3056 3057 3058 |
# File 'lib/pdfcrowd.rb', line 3055 def setDebugLog(value) @fields['debug_log'] = value self end |
#setDpi(dpi) ⇒ Object
3049 3050 3051 3052 |
# File 'lib/pdfcrowd.rb', line 3049 def setDpi(dpi) @fields['dpi'] = dpi self end |
#setHttpProxy(proxy) ⇒ Object
3097 3098 3099 3100 3101 3102 3103 3104 |
# File 'lib/pdfcrowd.rb', line 3097 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
3107 3108 3109 3110 3111 3112 3113 3114 |
# File 'lib/pdfcrowd.rb', line 3107 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
3010 3011 3012 3013 3014 3015 3016 3017 |
# File 'lib/pdfcrowd.rb', line 3010 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
3020 3021 3022 3023 3024 3025 3026 3027 |
# File 'lib/pdfcrowd.rb', line 3020 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
3000 3001 3002 3003 3004 3005 3006 3007 |
# File 'lib/pdfcrowd.rb', line 3000 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
3030 3031 3032 3033 3034 3035 3036 |
# File 'lib/pdfcrowd.rb', line 3030 def setMargins(top, right, bottom, left) setMarginTop(top) setMarginRight(right) setMarginBottom(bottom) setMarginLeft(left) self end |
#setMarginTop(top) ⇒ Object
2990 2991 2992 2993 2994 2995 2996 2997 |
# File 'lib/pdfcrowd.rb', line 2990 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
2960 2961 2962 2963 2964 2965 2966 2967 |
# File 'lib/pdfcrowd.rb', line 2960 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
2846 2847 2848 2849 2850 2851 2852 2853 |
# File 'lib/pdfcrowd.rb', line 2846 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
2970 2971 2972 2973 2974 2975 2976 2977 |
# File 'lib/pdfcrowd.rb', line 2970 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
2980 2981 2982 2983 2984 2985 2986 2987 |
# File 'lib/pdfcrowd.rb', line 2980 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
3145 3146 3147 3148 |
# File 'lib/pdfcrowd.rb', line 3145 def setProxy(host, port, user_name, password) @helper.setProxy(host, port, user_name, password) self end |
#setRemoveBorders(value) ⇒ Object
2917 2918 2919 2920 |
# File 'lib/pdfcrowd.rb', line 2917 def setRemoveBorders(value) @fields['remove_borders'] = value self end |
#setResize(resize) ⇒ Object
2856 2857 2858 2859 |
# File 'lib/pdfcrowd.rb', line 2856 def setResize(resize) @fields['resize'] = resize self end |
#setRetryCount(count) ⇒ Object
3151 3152 3153 3154 |
# File 'lib/pdfcrowd.rb', line 3151 def setRetryCount(count) @helper.setRetryCount(count) self end |
#setRotate(rotate) ⇒ Object
2862 2863 2864 2865 |
# File 'lib/pdfcrowd.rb', line 2862 def setRotate(rotate) @fields['rotate'] = rotate self end |
#setTag(tag) ⇒ Object
3091 3092 3093 3094 |
# File 'lib/pdfcrowd.rb', line 3091 def setTag(tag) @fields['tag'] = tag self end |
#setUseHttp(value) ⇒ Object
3127 3128 3129 3130 |
# File 'lib/pdfcrowd.rb', line 3127 def setUseHttp(value) @helper.setUseHttp(value) self end |
#setUserAgent(agent) ⇒ Object
3139 3140 3141 3142 |
# File 'lib/pdfcrowd.rb', line 3139 def setUserAgent(agent) @helper.setUserAgent(agent) self end |