/** * {@inheritdoc} */ public function duplicate($name) { $clone = new self($name); $clone->setContent($this->content); $clone->setChecksum($this->checksum); $clone->setMetadata($this->metadata); $clone->setMimeType($this->mimetype); $clone->setSize($this->size); if (null !== $this->lastAccess) { $clone->setLastAccess($this->lastAccess); } if (null !== $this->lastModification) { $clone->setLastModification($this->lastModification); } return $clone; }
/** * Create a new sourcemap based on sourceMappingURL with inline base64 encoded data * * Example: * //# sourceMappingURL=data:application/json;base64,.... * * @param string contents of the minified file including sourceMappingURL */ public static function createFromInline($fileContents) { // '//# sourceMappingURL=data:application/json;charset:utf-8;base64, // '//# sourceMappingURL=data:application/json;base64,' $pos = strrpos($fileContents, "\n//# sourceMappingURL="); $isCss = false; if ($pos === false) { $pos = strrpos($fileContents, "\n/*# sourceMappingURL="); if ($pos === false) { throw new Exception("No sourceMappingURL found"); } $isCss = true; } $url = substr($fileContents, $pos + 22); $url = rtrim($url); if ($isCss) { if (substr($url, -2) != '*/') { throw new Exception("sourceMappingURL isn't wrapped with closing */"); } $url = substr($url, 0, -2); //remove "*/" $url = rtrim($url); } if (substr($url, 0, 29) == 'data:application/json;base64,') { $map = substr($url, 29); } else { if (substr($url, 0, 29 + 14) == 'data:application/json;charset:utf-8;base64,') { $map = substr($url, 29 + 14); } else { throw new Exception("Unsupported sourceMappingURL"); } } $map = base64_decode($map); $map = json_decode($map); $fileContents = substr($fileContents, 0, $pos); $ret = new self($map, $fileContents); $ret->setMimeType($isCss ? 'text/css' : 'text/javascript'); return $ret; }
/** * * @param string $tmp_name path to file * @param string $type mime type * @return self * @throws Exception */ public static function createFromFile($tmp_name, $type) { $mime_type = ElggFile::detectMimeType($tmp_name, $type); if (false == in_array($mime_type, array("image/jpeg", "image/jpg"))) { register_error(elgg_echo("gallery_field:only_jpg")); return null; } $ext = "jpg"; $file = new self(); $thumb_file = new ElggFile(); $random_guid = self::genGUID(); $file->setFilename($random_guid . "." . $ext); $thumb_file->setFilename($random_guid . "_thumb." . $ext); $file->setMimeType($mime_type); $thumb_file->setMimeType($mime_type); $imgsizearray = getimagesize($tmp_name); if ($imgsizearray == false) { register_error("bad file"); return null; } $width = $imgsizearray[0]; $height = $imgsizearray[1]; $file->open("write"); $file->write(self::cropImage($tmp_name, $width, $height, 760, 580)); $file->close(); $file->access_id = 2; $thumb_file->open("write"); $thumb_file->write(self::cropImage($tmp_name, $width, $height, 200, 140)); $thumb_file->close(); $thumb_file->access_id = 2; $thumb_file->save(); $file->thumb_file_guid = $thumb_file->guid; $file->save(); return $file; }
/** * Read from a file * * @deprecated Use img.io.MetaDataReader instead * @param io.File file * @param var default default void what should be returned in case no data is found * @return img.util.ExifData * @throws lang.FormatException in case malformed meta data is encountered * @throws lang.ElementNotFoundException in case no meta data is available * @throws img.ImagingException in case reading meta data fails */ public static function fromFile(File $file) { if (FALSE === getimagesize($file->getURI(), $info)) { $e = new ImagingException('Cannot read image information from ' . $file->getURI()); xp::gc(__FILE__); throw $e; } if (!isset($info['APP1'])) { if (func_num_args() > 1) { return func_get_arg(1); } throw new ElementNotFoundException('Cannot get EXIF information from ' . $file->getURI() . ' (no APP1 marker)'); } if (!($info = exif_read_data($file->getURI(), 'COMPUTED,FILE,IFD0,EXIF,COMMENT,MAKERNOTE', TRUE, FALSE))) { throw new FormatException('Cannot get EXIF information from ' . $file->getURI()); } // Change key case for lookups foreach ($info as &$val) { $val = array_change_key_case($val, CASE_LOWER); } with($e = new self()); // COMPUTED info $e->setWidth(self::lookup($info['COMPUTED'], 'width')); $e->setHeight(self::lookup($info['COMPUTED'], 'height')); $e->setApertureFNumber(self::lookup($info['COMPUTED'], 'aperturefnumber')); // IFD0 info $e->setMake(trim(self::lookup($info['IFD0'], 'make'))); $e->setModel(trim(self::lookup($info['IFD0'], 'model'))); $e->setSoftware(self::lookup($info['IFD0'], 'software')); if (NULL !== ($o = self::lookup($info['IFD0'], 'orientation'))) { $e->setOrientation($o); } else { $e->setOrientation($e->width / $e->height > 1.0 ? 1 : 5); } // FILE info $e->setFileName(self::lookup($info['FILE'], 'filename')); $e->setFileSize(self::lookup($info['FILE'], 'filesize')); $e->setMimeType(self::lookup($info['FILE'], 'mimetype')); // EXIF info $e->setExposureTime(self::lookup($info['EXIF'], 'exposuretime')); $e->setExposureProgram(self::lookup($info['EXIF'], 'exposureprogram')); $e->setMeteringMode(self::lookup($info['EXIF'], 'meteringmode')); $e->setIsoSpeedRatings(self::lookup($info['EXIF'], 'isospeedratings')); // Sometimes white balance is in MAKERNOTE - e.g. FUJIFILM's Finepix if (NULL !== ($w = self::lookup($info['EXIF'], 'whitebalance'))) { $e->setWhiteBalance($w); } else { if (isset($info['MAKERNOTE']) && NULL !== ($w = self::lookup($info['MAKERNOTE'], 'whitebalance'))) { $e->setWhiteBalance($w); } else { $e->setWhiteBalance(NULL); } } // Extract focal length. Some models store "80" as "80/1", rip off // the divisor "1" in this case. if (NULL !== ($l = self::lookup($info['EXIF'], 'focallength'))) { sscanf($l, '%d/%d', $n, $frac); $e->setFocalLength(1 == $frac ? $n : $n . '/' . $frac); } else { $e->setFocalLength(NULL); } // Check for Flash and flashUsed keys if (NULL !== ($f = self::lookup($info['EXIF'], 'flash'))) { $e->setFlash($f); } else { $e->setFlash(NULL); } if (NULL !== ($date = self::lookup($info['EXIF'], 'datetimeoriginal', 'datetimedigitized'))) { $t = sscanf($date, '%4d:%2d:%2d %2d:%2d:%2d'); $e->setDateTime(new Date(mktime($t[3], $t[4], $t[5], $t[1], $t[2], $t[0]))); } return $e; }