Discussion:
specific file name for uploaded images - -small.jpg instead of 300x300.jpg
Adam LaBarge
2014-04-17 03:57:46 UTC
Permalink
I would like to be able to save a file similar to how WP does, but instead of the file size at the end of the file I want specific words.
Best I can find via searching online is: https://codex.wordpress.org/Class_Reference/WP_Image_Editor
And frankly I don't know if this is right or much less how to use it. Even the examples online are not very flushed out.http://wordpress.stackexchange.com/questions/91038/how-can-i-use-wp-save-image-editor-file-filterhttp://qandasys.info/hook-for-saving-an-image-after-editing/
Basically, I want for a custom image size the file to save instead of -300x300.jpg to be -small.jpg
Ideas?
BenderisGreat
2014-04-18 11:57:37 UTC
Permalink
I havent tested this, but it appears you can specify a filename yourself
using get_output_format(). Looks to be one of the accepted methods for
wp_get_image_editor().

So maybe something like :

function adams_image_mod( $path, $args ) {

$upload_to = wp_upload_dir();

$img = wp_get_image_editor( $path );
if ( !is_wp_error( $img ) ) {
$rename = $img->get_output_format( 'some-new-name' );
$saved = $img->save();

if($saved) {

wp_update_attachment_metadata( $id, $data );
}
}
}

return $img;

}


I didn't test this, its just an example - but Id imagine that is what the wp
devs put that in for. (make_image() and save() also accept filename args. )



--
View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/specific-file-name-for-uploaded-images-small-jpg-instead-of-300x300-jpg-tp43880p43886.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
Cristovao Verstraeten
2014-04-18 16:07:48 UTC
Permalink
Hi

If your question is about changing the size affix for images filenames
I've been wondering about this for some time too and have these links to
share:

http://bhoover.com/wp_image_editor-wordpress-image-editing-tutorial/
http://wordpress.stackexchange.com/questions/123240/rename-image-uploads-replacing-width-and-height-in-filename-with-medium
http://wordpress.stackexchange.com/questions/82193/rename-image-uploads-with-width-in-filename

Haven't got round to work on it so interested to know how you get along.

Greets,

-Cris.
Post by BenderisGreat
I havent tested this, but it appears you can specify a filename yourself
using get_output_format(). Looks to be one of the accepted methods for
wp_get_image_editor().
function adams_image_mod( $path, $args ) {
$upload_to = wp_upload_dir();
$img = wp_get_image_editor( $path );
if ( !is_wp_error( $img ) ) {
$rename = $img->get_output_format( 'some-new-name' );
$saved = $img->save();
if($saved) {
wp_update_attachment_metadata( $id, $data );
}
}
}
return $img;
}
I didn't test this, its just an example - but Id imagine that is what the wp
devs put that in for. (make_image() and save() also accept filename args. )
--
http://wordpress-hackers.1065353.n5.nabble.com/specific-file-name-for-uploaded-images-small-jpg-instead-of-300x300-jpg-tp43880p43886.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Cristovao Verstraeten
Jacob Van Lennepstraat 71
1053 HE Amsterdam
+31646549095 - http://apleasantview.com
Marko Heijnen
2014-04-23 15:05:23 UTC
Permalink
Hey,

The best solution would be extending WP_Image_Editor and creating your own.
What you then do is changing the method multi_resize(). You could then pass a better filename to the method _save().
This could then include the variable $size what is the name of the image size.

Best,

Marko
Post by Cristovao Verstraeten
Hi
If your question is about changing the size affix for images filenames
I've been wondering about this for some time too and have these links to
http://bhoover.com/wp_image_editor-wordpress-image-editing-tutorial/
http://wordpress.stackexchange.com/questions/123240/rename-image-uploads-replacing-width-and-height-in-filename-with-medium
http://wordpress.stackexchange.com/questions/82193/rename-image-uploads-with-width-in-filename
Haven't got round to work on it so interested to know how you get along.
Greets,
-Cris.
Post by BenderisGreat
I havent tested this, but it appears you can specify a filename yourself
using get_output_format(). Looks to be one of the accepted methods for
wp_get_image_editor().
function adams_image_mod( $path, $args ) {
$upload_to = wp_upload_dir();
$img = wp_get_image_editor( $path );
if ( !is_wp_error( $img ) ) {
$rename = $img->get_output_format( 'some-new-name' );
$saved = $img->save();
if($saved) {
wp_update_attachment_metadata( $id, $data );
}
}
}
return $img;
}
I didn't test this, its just an example - but Id imagine that is what the wp
devs put that in for. (make_image() and save() also accept filename args. )
--
http://wordpress-hackers.1065353.n5.nabble.com/specific-file-name-for-uploaded-images-small-jpg-instead-of-300x300-jpg-tp43880p43886.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Cristovao Verstraeten
Jacob Van Lennepstraat 71
1053 HE Amsterdam
+31646549095 - http://apleasantview.com
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...