GC_Image_Editor::generate_filename()
最后更新于:2021-11-27 23:34:30
GC_Image_Editor::generate_filename( string$suffix=null, string$dest_path=null, string$extension=null)Builds an output filename based on current file, and adding proper suffix
参数
- $suffix
-
(string) (Optional)
Default value: null
- $dest_path
-
(string) (Optional)
Default value: null
- $extension
-
(string) (Optional)
Default value: null
响应
(string) filename
源文件
文件: gc-includes/class-gc-image-editor.php
public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) {
// $suffix will be appended to the destination filename, just before the extension.
if ( ! $suffix ) {
$suffix = $this->get_suffix();
}
$dir = pathinfo( $this->file, PATHINFO_DIRNAME );
$ext = pathinfo( $this->file, PATHINFO_EXTENSION );
$name = gc_basename( $this->file, ".$ext" );
$new_ext = strtolower( $extension ? $extension : $ext );
if ( ! is_null( $dest_path ) ) {
if ( ! gc_is_stream( $dest_path ) ) {
$_dest_path = realpath( $dest_path );
if ( $_dest_path ) {
$dir = $_dest_path;
}
} else {
$dir = $dest_path;
}
}
return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}";
}