简体   繁体   中英

Drupal 7 image_style_url not creating the styled image

I have the following codes to test the image_style_url() on the latest drupal(v7.59)

<img src=“<?= file_create_url($fileuri); ?>” />
<img src=“<?= image_style_url(“medium”, $fileuri); ?>” />

The file_create_url() can show the original image properly, and the image_style_url() can only give the styled image url, but not creating any styled image in the styled image folder.

the public:// and the /tmp directriea are in 777 permission setting, so it won't be related to permission problem.

Can someone tell me what is wrong with my drupal?

Seems you have to create the image derivate first. Normally this happens automatically when uploading an image via an image field upload. But the automatic derivate creating might simply get skipped on file field uploads, or when using some other image which isn't managed by Drupal at all, or when you added an image style after you already uploaded the image.

Have a look at image_style_create_derivative($style, $source, $destination) . Check out the comments as well as $style needs to be an array returned by image_style_load('MYSTYLE') .

Creates a new image derivative based on an image style.

Only issue left open is how to check first if the derivate already exists before calling that function. Maybe you can check what file_exists(image_style_path($style_name, $file_uri)) returns, first.


Read more: https://drupal.stackexchange.com/a/22555/15055

Nothing wrong with your Drupal. Derivative image is not physically created until someone visits the listing where that style is used.

Example: You create new node and upload an image on it. Original image is within files folder. But if you use for example teaser image style and if you go to teaser folder the image is not created there until someone visits the page where "teaser" image style is used. You can easily test this on clean Drupal. Basically the image is created on the fly on HTTP request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM