Create an image size with B&W image in Wordpress on regenerate thumbnails The Next CEO of Stack OverflowQuestion about image thumbnail performance in PHPSizing images to thumbnail size in WordPresswordpress post-thumbnail crop question. is this even possible?Image resize increment file sizeForce Wordpress to create Thumbnails of same Size as the uploaded ImageChanging image size in MarkdownWordpress getting thumnails of images in custom fieldsProgrammatically Creating Thumbnails in Wordpress Displays Image As BinaryHow to call a custom thumbnail image size in WordPress when coming from a field?WordPress's wp_get_attachment_image_srcset is not returning all the image srcset sizes

Describing a person. What needs to be mentioned?

Does it take more energy to get to Venus or to Mars?

Need some help with wall behind rangetop

Can a single photon have an energy density?

Increase performance creating Mandelbrot set in python

How do I go from 300 unfinished/half written blog posts, to published posts?

How to make a software documentation "officially" citable?

If I blow insulation everywhere in my attic except the door trap, will heat escape through it?

How do I construct this japanese bowl?

If the heap is initialized for security, then why is the stack uninitialized?

Should I tutor a student who I know has cheated on their homework?

MAZDA 3 2006 (UK) - poor acceleration then takes off at 3250 revs

What do "high sea" and "carry" mean in this sentence?

Implement the Thanos sorting algorithm

Why doesn't a table tennis ball float on the surface? How do we calculate buoyancy here?

How did people program for Consoles with multiple CPUs?

How to use tikz in fbox?

Science fiction (dystopian) short story set after WWIII

How do I get the green key off the shelf in the Dobby level of Lego Harry Potter 2?

Why does C# sound extremely flat when saxophone is tuned to G?

Term for the "extreme-extension" version of a straw man fallacy?

Are there languages with no euphemisms?

Where to find order of arguments for default functions

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin



Create an image size with B&W image in Wordpress on regenerate thumbnails



The Next CEO of Stack OverflowQuestion about image thumbnail performance in PHPSizing images to thumbnail size in WordPresswordpress post-thumbnail crop question. is this even possible?Image resize increment file sizeForce Wordpress to create Thumbnails of same Size as the uploaded ImageChanging image size in MarkdownWordpress getting thumnails of images in custom fieldsProgrammatically Creating Thumbnails in Wordpress Displays Image As BinaryHow to call a custom thumbnail image size in WordPress when coming from a field?WordPress's wp_get_attachment_image_srcset is not returning all the image srcset sizes










0















Looking for a way to regenerate all my featured images and that it will create a new image size in B&W,



I know this can be done in CSS but I need to pull this image with REST to a JS canvas application and cannot use CSS,



I found this code but it does not seem to work in my case,
It works on some pages with I upload images but not when I upload the image to a post, also I was wondering if there is a way to do this with Regenerate of all the thumbnails on site and not on upload.



add_action('after_setup_theme','themename_bw_size');
function themename_bw_size()
add_image_size('themename-bw-image', 100, 100, true);


add_filter('wp_generate_attachment_metadata','themename_bw_filter');
function themename_bw_filter($meta)
$file = wp_upload_dir();
$file = trailingslashit($file['path']).$meta['sizes']['themename-bw-image']['file'];
list($orig_w, $orig_h, $orig_type) = @getimagesize($file);
$image = wp_load_image($file);
imagefilter($image, IMG_FILTER_GRAYSCALE);
switch ($orig_type)
case IMAGETYPE_GIF:
imagegif( $image, $file );
break;
case IMAGETYPE_PNG:
imagepng( $image, $file );
break;
case IMAGETYPE_JPEG:
imagejpeg( $image, $file );
break;

return $meta;



Thanks!










share|improve this question






















  • Hello Alon, welcome to SO. What exactly does not seem to work?

    – Olafant
    Mar 7 at 17:02











  • Where have you added this code? Also, is there are reason you're using calling add_image_size is the after_setup_theme action?

    – FluffyKitten
    Mar 7 at 21:29











  • The code does create a new image size, what I'm looking for is to get the code to create the new B&W image size with the greyscale filter when regenerating the thumbnails. I have more then 600 images on site I would like to create a B&W image from,

    – Alon Katziri
    Mar 8 at 20:55















0















Looking for a way to regenerate all my featured images and that it will create a new image size in B&W,



I know this can be done in CSS but I need to pull this image with REST to a JS canvas application and cannot use CSS,



I found this code but it does not seem to work in my case,
It works on some pages with I upload images but not when I upload the image to a post, also I was wondering if there is a way to do this with Regenerate of all the thumbnails on site and not on upload.



add_action('after_setup_theme','themename_bw_size');
function themename_bw_size()
add_image_size('themename-bw-image', 100, 100, true);


add_filter('wp_generate_attachment_metadata','themename_bw_filter');
function themename_bw_filter($meta)
$file = wp_upload_dir();
$file = trailingslashit($file['path']).$meta['sizes']['themename-bw-image']['file'];
list($orig_w, $orig_h, $orig_type) = @getimagesize($file);
$image = wp_load_image($file);
imagefilter($image, IMG_FILTER_GRAYSCALE);
switch ($orig_type)
case IMAGETYPE_GIF:
imagegif( $image, $file );
break;
case IMAGETYPE_PNG:
imagepng( $image, $file );
break;
case IMAGETYPE_JPEG:
imagejpeg( $image, $file );
break;

return $meta;



Thanks!










share|improve this question






















  • Hello Alon, welcome to SO. What exactly does not seem to work?

    – Olafant
    Mar 7 at 17:02











  • Where have you added this code? Also, is there are reason you're using calling add_image_size is the after_setup_theme action?

    – FluffyKitten
    Mar 7 at 21:29











  • The code does create a new image size, what I'm looking for is to get the code to create the new B&W image size with the greyscale filter when regenerating the thumbnails. I have more then 600 images on site I would like to create a B&W image from,

    – Alon Katziri
    Mar 8 at 20:55













0












0








0








Looking for a way to regenerate all my featured images and that it will create a new image size in B&W,



I know this can be done in CSS but I need to pull this image with REST to a JS canvas application and cannot use CSS,



I found this code but it does not seem to work in my case,
It works on some pages with I upload images but not when I upload the image to a post, also I was wondering if there is a way to do this with Regenerate of all the thumbnails on site and not on upload.



add_action('after_setup_theme','themename_bw_size');
function themename_bw_size()
add_image_size('themename-bw-image', 100, 100, true);


add_filter('wp_generate_attachment_metadata','themename_bw_filter');
function themename_bw_filter($meta)
$file = wp_upload_dir();
$file = trailingslashit($file['path']).$meta['sizes']['themename-bw-image']['file'];
list($orig_w, $orig_h, $orig_type) = @getimagesize($file);
$image = wp_load_image($file);
imagefilter($image, IMG_FILTER_GRAYSCALE);
switch ($orig_type)
case IMAGETYPE_GIF:
imagegif( $image, $file );
break;
case IMAGETYPE_PNG:
imagepng( $image, $file );
break;
case IMAGETYPE_JPEG:
imagejpeg( $image, $file );
break;

return $meta;



Thanks!










share|improve this question














Looking for a way to regenerate all my featured images and that it will create a new image size in B&W,



I know this can be done in CSS but I need to pull this image with REST to a JS canvas application and cannot use CSS,



I found this code but it does not seem to work in my case,
It works on some pages with I upload images but not when I upload the image to a post, also I was wondering if there is a way to do this with Regenerate of all the thumbnails on site and not on upload.



add_action('after_setup_theme','themename_bw_size');
function themename_bw_size()
add_image_size('themename-bw-image', 100, 100, true);


add_filter('wp_generate_attachment_metadata','themename_bw_filter');
function themename_bw_filter($meta)
$file = wp_upload_dir();
$file = trailingslashit($file['path']).$meta['sizes']['themename-bw-image']['file'];
list($orig_w, $orig_h, $orig_type) = @getimagesize($file);
$image = wp_load_image($file);
imagefilter($image, IMG_FILTER_GRAYSCALE);
switch ($orig_type)
case IMAGETYPE_GIF:
imagegif( $image, $file );
break;
case IMAGETYPE_PNG:
imagepng( $image, $file );
break;
case IMAGETYPE_JPEG:
imagejpeg( $image, $file );
break;

return $meta;



Thanks!







php wordpress image






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 14:25









Alon KatziriAlon Katziri

1




1












  • Hello Alon, welcome to SO. What exactly does not seem to work?

    – Olafant
    Mar 7 at 17:02











  • Where have you added this code? Also, is there are reason you're using calling add_image_size is the after_setup_theme action?

    – FluffyKitten
    Mar 7 at 21:29











  • The code does create a new image size, what I'm looking for is to get the code to create the new B&W image size with the greyscale filter when regenerating the thumbnails. I have more then 600 images on site I would like to create a B&W image from,

    – Alon Katziri
    Mar 8 at 20:55

















  • Hello Alon, welcome to SO. What exactly does not seem to work?

    – Olafant
    Mar 7 at 17:02











  • Where have you added this code? Also, is there are reason you're using calling add_image_size is the after_setup_theme action?

    – FluffyKitten
    Mar 7 at 21:29











  • The code does create a new image size, what I'm looking for is to get the code to create the new B&W image size with the greyscale filter when regenerating the thumbnails. I have more then 600 images on site I would like to create a B&W image from,

    – Alon Katziri
    Mar 8 at 20:55
















Hello Alon, welcome to SO. What exactly does not seem to work?

– Olafant
Mar 7 at 17:02





Hello Alon, welcome to SO. What exactly does not seem to work?

– Olafant
Mar 7 at 17:02













Where have you added this code? Also, is there are reason you're using calling add_image_size is the after_setup_theme action?

– FluffyKitten
Mar 7 at 21:29





Where have you added this code? Also, is there are reason you're using calling add_image_size is the after_setup_theme action?

– FluffyKitten
Mar 7 at 21:29













The code does create a new image size, what I'm looking for is to get the code to create the new B&W image size with the greyscale filter when regenerating the thumbnails. I have more then 600 images on site I would like to create a B&W image from,

– Alon Katziri
Mar 8 at 20:55





The code does create a new image size, what I'm looking for is to get the code to create the new B&W image size with the greyscale filter when regenerating the thumbnails. I have more then 600 images on site I would like to create a B&W image from,

– Alon Katziri
Mar 8 at 20:55












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55046114%2fcreate-an-image-size-with-bw-image-in-wordpress-on-regenerate-thumbnails%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55046114%2fcreate-an-image-size-with-bw-image-in-wordpress-on-regenerate-thumbnails%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved