+ {
+ $targetType = $this->preferredType();
+ $outname = Avatar::filename($this->id,
+ image_type_to_extension($targetType),
+ $size,
+ common_timestamp());
+ $outpath = Avatar::path($outname);
+ $this->resizeTo($outpath, $size, $size, $x, $y, $w, $h);
+ return $outname;
+ }
+
+ /**
+ * Copy the image file to the given destination.
+ * For obscure formats, this will automatically convert to PNG;
+ * otherwise the original file will be copied as-is.
+ *
+ * @param string $outpath
+ * @return string filename
+ */
+ function copyTo($outpath)
+ {
+ return $this->resizeTo($outpath, $this->width, $this->height);
+ }
+
+ /**
+ * Create and save a thumbnail image.
+ *
+ * @param string $outpath
+ * @param int $width target width
+ * @param int $height target height
+ * @param int $x (default 0) upper-left corner to crop from
+ * @param int $y (default 0) upper-left corner to crop from
+ * @param int $w (default full) width of image area to crop
+ * @param int $h (default full) height of image area to crop
+ * @return string full local filesystem filename
+ */
+ function resizeTo($outpath, $width, $height, $x=0, $y=0, $w=null, $h=null)