Browse Source

增加setDefaultResourcePhoto方法和save方法

zzy.zhiyuan.foxmail 8 years ago
parent
commit
f7348ca306
1 changed files with 29 additions and 0 deletions
  1. 29 0
      src/main/java/com/ekexiu/portal/service/ImageService.java

+ 29 - 0
src/main/java/com/ekexiu/portal/service/ImageService.java

25
	private File imagePath;
25
	private File imagePath;
26
	private File headPath;
26
	private File headPath;
27
	private File orgPath;
27
	private File orgPath;
28
	private File resourcePath;
28
	private int largeHeadPhotoWidth = 200;
29
	private int largeHeadPhotoWidth = 200;
29
	private int largeHeadPhotoHeight = 200;
30
	private int largeHeadPhotoHeight = 200;
30
	private int middleHeadPhotoWidth = 200;
31
	private int middleHeadPhotoWidth = 200;
34
35
35
	private File defaultHeadPhoto;
36
	private File defaultHeadPhoto;
36
	private File defaultOrgLogo;
37
	private File defaultOrgLogo;
38
	private File defaultResourcePhoto;
37
39
38
	private byte[] dli;
40
	private byte[] dli;
39
	private byte[] dmi;
41
	private byte[] dmi;
40
	private byte[] dsi;
42
	private byte[] dsi;
41
	private byte[] dol;
43
	private byte[] dol;
44
	private byte[] dsl;
42
45
43
	public File getDefaultHeadPhoto() {
46
	public File getDefaultHeadPhoto() {
44
		return defaultHeadPhoto;
47
		return defaultHeadPhoto;
129
	public void setTmpDir(File tmpPath) {
132
	public void setTmpDir(File tmpPath) {
130
		this.tmpPath = tmpPath;
133
		this.tmpPath = tmpPath;
131
	}
134
	}
135
	
136
	public File getDefaultResourcePhoto() {
137
		return defaultResourcePhoto;
138
	}
139
140
	public void setDefaultResourcePhoto(File defaultResourcePhoto) {
141
		this.defaultResourcePhoto = defaultResourcePhoto;
142
	}
132
143
133
	private File getTemplateFielName(File path, String suffix) {
144
	private File getTemplateFielName(File path, String suffix) {
134
		File result = null;
145
		File result = null;
226
				this.dmi = this.zoomImage(dd, this.middleHeadPhotoWidth, this.middleHeadPhotoHeight);
237
				this.dmi = this.zoomImage(dd, this.middleHeadPhotoWidth, this.middleHeadPhotoHeight);
227
				this.dsi = this.zoomImage(dd, this.smallHeadPhotoWidth, this.smallHeadPhotoHeight);
238
				this.dsi = this.zoomImage(dd, this.smallHeadPhotoWidth, this.smallHeadPhotoHeight);
228
				this.dol = IoUtil.readStream(new FileInputStream(this.defaultOrgLogo), true);
239
				this.dol = IoUtil.readStream(new FileInputStream(this.defaultOrgLogo), true);
240
				this.dsl = IoUtil.readStream(new FileInputStream(this.defaultResourcePhoto), true);
229
			} catch (IOException e) {
241
			} catch (IOException e) {
230
				this.dli = null;
242
				this.dli = null;
231
				this.dmi = null;
243
				this.dmi = null;
232
				this.dsi = null;
244
				this.dsi = null;
233
				this.dol = null;
245
				this.dol = null;
246
				this.dsl = null;
234
				throw new RuntimeException("init image error", e);
247
				throw new RuntimeException("init image error", e);
235
			}
248
			}
236
		}
249
		}
247
		this.initDefaultImage();
260
		this.initDefaultImage();
248
		IoUtil.saveStream(new FileOutputStream(new File(this.orgPath, id + ".jpg")), this.dol, true);
261
		IoUtil.saveStream(new FileOutputStream(new File(this.orgPath, id + ".jpg")), this.dol, true);
249
	}
262
	}
263
	
264
	public void saveDefaultResourcePhoto(String resourceId) throws IOException {
265
		this.initDefaultImage();
266
		IoUtil.saveStream(new FileOutputStream(new File(this.resourcePath, resourceId + ".jpg")), this.dsl, true);
267
	}
250
268
251
	@Post
269
	@Post
252
	@Path("/org")
270
	@Path("/org")
258
			in.close();
276
			in.close();
259
		}
277
		}
260
	}
278
	}
279
	
280
	@Post
281
	@Path("/resoure")
282
	public void saveResourcePhoto(String resourceId, String fn) throws IOException {
283
		InputStream in = new FileInputStream(new File(this.tmpPath, fn));
284
		try {
285
			IoUtil.copy(in, new FileOutputStream(new File(this.resourcePath, resourceId + ".jpg")), false, true);
286
		} finally {
287
			in.close();
288
		}
289
	}
261
290
262
	@Post
291
	@Post
263
	@Path("/head")
292
	@Path("/head")