syamilmj / aqua-resizer Goto Github PK
View Code? Open in Web Editor NEWResize WordPress images on the fly
Resize WordPress images on the fly
Hello,
In my localhost WP theme I have this line of code
It doesn't create any link. It seems that the problem is that the source image isn't on the same url as aqua_resizer script.
Thank you for this great script.
Hi. I found issue #13 regarding incorporation of jetpack photon for the presentation of thumbnails.
I tried the solution presented in the comments with one of WPExplorer's themes - 'Adapt' and it works! I will be incorporating this as a child theme to wpex-adapt. The only problem was 'apply_filter' should be 'apply_filters'.
Thanks for your help and comments to issue #13
I have seen this issue, but the fix given there is not applicable at the moment:
#13
Is there anyway we can get this to work?
We're finding that when images are being deleted via WP admin, some of the resized image files are also deleted, but others are being left in the uploads folder. Then, if a new image with the same filename is uploaded, the resized files that Aqua Resizer creates are given filenames that have a number suffix included, and when the image needs to be shown on the website, the wrong one is appearing.
For example:
An image called "steve-i-phone-021.jpg" is uploaded. Various resized versions are created, including "steve-i-phone-021-700x350.jpg".
That image is deleted via WP admin, and most of the resized images are also deleted, but "steve-i-phone-021-700x350.jpg" is NOT deleted, and it stays in the uploads folder.
A different image which has the same name "steve-i-phone-021.jpg" is now uploaded. Various resized versions are created, but the one for 700x350px is given the name "steve-i-phone-0211-700x350.jpg" because "steve-i-phone-021-700x350.jpg" already exists (note the extra "1" in the filename).
Now, when the 700x350px version needs to be shown on the website, Aqua Resizer is showing the original "steve-i-phone-021-700x350.jpg", i.e. the old image which is the wrong one, that should have been deleted.
There is the problem when "domain per language" option is selected in WPML.
ex. domain.local and en.domain.local.
In that case function is returning "false".
If you want true server cache, attachment metadata and stuff like that you're welcome to post here.
Make sure to be as detailed as possible. Reference to codex, other scripts, general examples etc would be tremendously helpful.
Cheers
Not an issue I know ;)
Apologies if i've missed this, but is it possible to set crop sizes etc for an image upload via the SMOF Media Uploader (ie; a profile image for an About section)?
And how to output this correctly.
thanks in advance
Hi
First Great script, light and straight forward
I am wondering if there is a way to delete generate files from media library
thanks in advance
Hi,
I have an issue on my website : http://www.sudtrotting.com/
On thumbnails, the horses' heads (or actually the borders of the images) are cropped out. I would like them to still be visible, any ideas ?
I tried fixing it by myself but am not a PHP expert so couldn't find any way.
Even a hot fix would be nice.
Thanks a lot !
Hi,
I use this script in one of my plugin. For a server with file permission 755, resized image url not executing. I change wp-content folder file permission to 777 and it's start executing.
You may know 777 permission is not safe. What to do now?
Thanks in advance
Is it possible to combine feature image or first image in post as the thumbnail?
In case user don't set up feature image, automatically will use the first post image as thumbnail.
In traditional way, I use this code:
<?php
$size = 'thumbnail'; // whatever size you want
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'thumb-600' );
} else {
$attachments = get_children( array(
'post_parent' => get_the_ID(),
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ID',
'numberposts' => 1)
);
foreach ( $attachments as $thumb_id => $attachment )
echo wp_get_attachment_image($thumb_id, $size);
}
?>
How can I implement these code when I'm using Aqua-resizer?
Or maybe you have better solution?
Thanks in advance.
This is not an issue but i donno where to upload ur library file in wordpress?
I've run into an issue, or at least an issue that I've noticed, that if a user uploads an image smaller than the image crop is specified, the image doesn't show at all. For example if I have set 250px x 250px to show in a gallery, and a user tries to display an image that is 200px x 200px, then the image doesn't show.
Is this an issue or is it something I'm doing wrong?
Thanks!
Justin
I would love to have a little discussion about the use of Aqua-Resizer. Following:
I came a little bit in trouble when I had a brainstorming how to realize retina support and do it well while using Aqua-Resizer. In fact, technically it's not that hard to just save a @2x file along with the default one.
But then: How to tell the user in the backend (and when I think this is a serious concern for the AQ-developers here, as some of them may be authors on Themeforest ;) ) if the current image is large enough for retina generation. Of course, one could let this just let alone on the user, but I really wish I could provide something like http://wordpress.org/extend/plugins/wp-retina-2x/ - which would be possible by common WP thumb generation.
I think of that like adding a variable add_image_size('custom_size', $width, $height) function in the functions.php which would get just measures which the user typed in the admin panel. Typing the_post_thumbnail('custom_size') instead of aq_resize() would have almost the same effect, just that the generated files would be tracked and so the plugin I posted above would flawlessly work.
I appreciate any thoughts by everyone. If there is going to materialize some good approach for Aqua-Resizer, I will implement that and in the same run make it a class.
Hey friend,
It doesn't seem like JetPack Photon works when using aqua resizer (in my case) I'd really like to get these two working together. Have you any experience with this or heard about this from someone else?
WordPress resizing functions is really dumb.
If you set the resize dimensions larger than the original image dimensions, no resizing or cropping will be performed.
BUT you can use the crop method to enlarge photos.
Also, adding $editor->set_quality( 100 ); by default, would be good.
Guys,
I'm having issue with this script. It does not work on some site. This site, i work with, using subdomain. Here the site: http://babybook.bg/blog/
I'm using this function:
function get_first_image() {
global $post;
$id = get_post_thumbnail_id();
$imgurl = wp_get_attachment_image_src($id, 'large');
$thumbs = get_children(array (
'post_parent' => $post->ID,
'post_type' => 'attachment',
'numberposts' => 1,
'post_status' => null,
'post_mime_type' => 'image',
));
```
if (has_post_thumbnail()) { // check for featured image
$id = get_post_thumbnail_id();
$imgurl = wp_get_attachment_image_src($id, 'large');
$imgurl = $imgurl[0];
} elseif ($thumbs) { // if no featured image, go with attached images
foreach ($thumbs as $thumb) {
$img = wp_get_attachment_image_src($thumb->ID, 'large');
$imgurl = $img[0];
}
}
return $imgurl;
}
// Credit to Aqua Resizer by Syamil MJ
function image_attachment($key, $width, $height, $crop) {
global $post;
$img_url = get_first_image(); //get full URL to image (use "large" or "medium" if the images too big)
$image = aq_resize( $img_url, $width, $height, $crop ); //resize & crop the image
if($image) {
echo '<img src="'.$image.'" alt="Thumbnail_zero_attch"/>';
}
else { //else, return
return;
}
}
```
And this is how I echo the image
<?php $img_url = get_first_image(); $image = aq_resize( $img_url, 240, 'auto', false ); if($image) : ?>
<?php echo '<img src="'.$image.'" alt="thumbnail_3rika"/>'; ?>
<?php endif; ?>
Tried with this also (example 1), https://github.com/syamilmj/Aqua-Resizer/wiki/Examples, but it does not work. So i believe this is not the function issue.
All image is attached properly, btw. But what make it weird is, it works on some post, old post actually. But when I try creating a new one, it does not work at all.
I have updated the script to the latest version and issue persist. The theme is installed in so many sites, but only two of them that can not run this script properly.
Hi!!! Im using a Wordpress theme that uses Aqua-Resizer.
Everything works on development, but not on Heroku where Im hosting my staging and production environment.
Since Heroku has a read-only filesystem (except for temporary files) I use a plugin to upload to S3 and uploads work ok. Maybe this could be causing the problem...
I confirmed the problem is here since using the unprocessed url for the image works fine.
Changelog says there is a v1.2, but I'm not seeing it.
I'm currently getting a Notice: image_resize is deprecated
using WP 3.6.1.
Is v1.2 available with a fix to this issue?
I tried your resize script and so far it seems to be working. I am not sure I know what I am doing so I would like for you to check my code please.
I made a widget in the functions.php file. I took code from your example on this page and turned it into a function. Then I called that function in my widget which is displaying in the sidebar. Here is a chunk form my widget
<?php $loop = new WP_Query( array( 'post_type' => 'gallery', 'posts_per_page' => 6 ) ); ?>
<ul class="gallery">
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li><?php savior_resize('74', '74', true); ?></li>
<?php endwhile; wp_reset_query();?>
</ul>
The loop above queries a custom post type. Then in the functions.php file, I put in this function.
function savior_resize($height, $width, $crop){
$thumb = get_post_thumbnail_id();
$img_url = wp_get_attachment_url( $thumb,'full' );
$image = aq_resize( $img_url, $height, $width, true );
echo '<img src="'.$image.'" />';
}
What I don't understand is how to get this script to replace the_post_thumbnail? I hate using add_image_size. I added three sizes today and have been working for 4 hours trying to get the right size to show up in the sidebar. I finally added your script and had it working in 5 minutes. So how do I get this script to replace the add_image_size crap so that no matter what image is uploaded through the uploader, the proper size will display. for the sidebar, gallery, post and pages, I pretty much know what size I want but I have to code the the ability for the user to select his own size. Can you offer any advice on how to use this code of yours effectively?
The Wiki and Function parameter documentation at the top of the process function specify that either height OR width are required. The process functions forces both to be defined, or an error is thrown.
Hello! I would like to contribute with a few changes to Aqua Resizer, but I'm new to Github and I'm not really sure if I made the commit the right way. If you didn't get it, here is the fork I made: https://github.com/S3bY/Aqua-Resizer
My addition is image metadata, so all images created by the script be deleted from the server when the original is removed.
I also added the retina display support suggested by wpexplorer in this thread: #36
Hi there,
Awesome plugin - could shoot myself as I just discovered it.
I'm having a issue with resizing images retrieved from a post gallery. I'm not sure if this is an issue with aq_resizer or my wordpress skills (lack there of). The URL's are output as aq_resizer requires, but as soon as I pass $image through the aq_resize function it outputs nothing.
Below is my code:
$gallery = get_post_gallery_images();
$image_list = '<ul>';
// Loop through each image in each gallery
foreach( $gallery as $image ) {
$imagethumb = aq_resize($image, 75, 75, true);
$image_list .= '<li><img src="' . $image . '"/></li>';
}
$image_list .= '</ul>';
$content .= $image_list;
echo $content;
Any help would be appreciated, thanks in advance.
How do you go about integrating lazy loading with this script?
Below is the lazy loading script I had in mind.
https://wordpress.org/plugins/rocket-lazy-load/
Hi I have some images that reside in the root folder of my wordpress install in a certain structure that I need to keep. However I would like to use aqua resizer for using these images since my theme supports it.
It does not look to hard to actually pull images from a folder inside WP and put them in the upload folder. Would this be a feature in the near future to be considered?
My Theme comes with the 1.1.6 version and I think I am going to hack it up to fit my needs, I might do a pull request in the near future if anyone would be interested.
Hello,
i use your script for almost 2 years now and it is excellent, never had a problem with it.
Thank you for your hard work to make ours easier!
I have encountered an issue recently:
a website is hosted on a subdomain on wpengine.com, but the website redirects to a domain name. ( bgw.wpengine.com --> http://blessinggodsway.com/ ).
im 100% sure that the images won
t load the images because of this.
i`m using the latest version of the script.
do you know how to get around this? is there any fix?
maybe the script is dependent on some PHP libraries, which may be unavailable on WPEngine?
any help with this is appreciated!
thank you,
andi
Hi,
animated gif does not cropped blank blank src=โโ
Has anyone been able to get Aqua re-sizer working with Amazon S3? I get a lot of frustrated customers who want to host their images externally. I'm not really sure what to tell them. I usually just point them to how they disable the cropping and just return the $url.
Wondering how you guys are handling it? Or there is a potential way to get it working with S3.
Thanks!
AJ
I am trying to resize the images in the theme files, but it did't print any image to frontend. but it is working fine in the localhost. I didn't understand what is wrong with my theme files or aqua resizer. I have a website which is having more than 50K images on it, Now i am going to change the theme for the website so i need to regenerate the thumbnails or resize them, i found the aqua resizer is doing it's job very well, and fits my need of the website;
Would it be possible to apply a custom meta ID to images added using aqua resizer and then have a function that can loop through these and delete them? This way if someone stops using a theme that uses aqua resizer they could easily delete all images created by the script?
Or even be able to have a button in the theme panel that deletes them.
Would love to see some sort of system like this and of course would donate for the update ;)
Hi there,
Excellent script.
I've had a number of my customers tell me that their images do not display when they use SSL and switch to https in the URL. I'm surprised to see nobody else appears to have brought this up, is there any fix for this, or is it a script issue at all?
Has anyone been able to get aqua_resizer working for people using Amazon S3 to store their images?
If not, I'm wondering what sort of advice are you giving to your customers who are trying to use your themes which use Aqua Resizer.
Thanks!
Timthumb has a way to set the crop alignment
http://www.binarymoon.co.uk/2010/08/timthumb-part-4-moving-crop-location/
so like a=t
Is that possible with this?
Any chance of integrating crop positioning using the new WP_get_image_editor function? I know it would take way too much to integrate into image_resize, but it's already built into the new function.
Thanks!
Tom
Hey
This is Lucy with WP Rocket (http://wp-rocket.me), a premium caching plugin with more than 5000 users. We would really like to be fully compatible with Aqua Resizer, but it causes some problems with our CDN function. If you could add filters on your returns, we would be able to hook on to it and make sure all the images get added to the CDN. This would make a lot of our customers happy :)
Feel free to email me directly to discuss further: lucy @ wp-rocket.me
Thanks!
Hi,
I'm a webdesigner using a wordpress theme i bought some time ago but the theme & theme builder have disappeared online. No updates and support available anymore.
The theme is using aqua page builder and aqua resizer.
It's all working fine, but the resized images don't look sharp.
They look fine on my portfolio page, but on the homepage (where they are smaller) they're unsharp.
How can i solve this?
I'm not a developer, no php experience. But i can look up some code and change it if someone could point me in the right direction.
Thank you very much!
Anneleen
Here is the code I came up with and it seems to work pretty good, thought I'd share it with everyone (just add it before return $image; )
// RETINA Support ---------------------------------------------------------------> $retina_w = $dst_w*2; $retina_h = $dst_h*2; //get image size after cropping $dims_x2 = image_resize_dimensions($orig_w, $orig_h, $retina_w, $retina_h, $crop); $dst_x2_w = $dims_x2[4]; $dst_x2_h = $dims_x2[5]; // If possible lets make the @2x image if($dst_x2_h) { //@2x image url $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}@2x.{$ext}"; //check if retina image exists if(file_exists($destfilename) && getimagesize($destfilename)) { // already exists, do nothing } else { // doesnt exist, lets create it $editor = wp_get_image_editor($img_path); if ( ! is_wp_error( $editor ) ) { $editor->resize( $retina_w, $retina_h, $crop ); $editor->set_quality( 100 ); $filename = $editor->generate_filename( $dst_w . 'x' . $dst_h . '@2x' ); $editor = $editor->save($filename); } } }
Then just include retina.js with your theme and you are good to go - http://retinajs.com/
Is there any way to resize images using your plugin even though they were not uploaded by wordpress?
Would appreciate that a lot!
when image size smaller than crop size so image will not show. There is any solution for it image will remain show on crop size.
Thanks
I want to use resizer with 9999 parameter which allows for unlimited height. The problem is line 113 "if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) )" Could somebody shed light on what is the purpose of of it ?
Images that are passed in with the exact measurements for resizing end up returning false as opposed to returning the original image:
Line 102:
if ( ! $dims && ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) {
Should be:
if ( ! $dims || ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) {
rather then returning false:
if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) {
// Can't resize, so return false saying that the action to do could not be processed as planned.
return false;
}
This should probably just return the main image ($url). Better to show an un-cropped image then a broken image. No?
Is this supports multisite?
Hi, I use the Aqua-Resizer script for my some themes. Some user has a little problem.
The script resize perfectly the images, but all images is pixelated. I think the problem is the server/hosting.
A possible fix or solution? I read all issue/docs but I don't find anything.
This is the screenshot: http://cl.ly/image/0x1P34052w29
Thanks for your time.
The local url check on line 35 does not work when WPML is set to use a different directory for the languages (e.g. http://www.smartcode.ch/de for german).
The current check, using home_url()
fails, since this function does return http://www.smartcode.ch/de
if on the german page.
I suggest to replace home_url()
with $upload_url
(defined on line 32), which is wp_upload_dir() -> baseurl
on line 35 to check if the image url ($url
) is local.
Hii am running an entertainment website where am using wp theme , the problem is I cant see my website index page in a mobile view . I tried every browser and app but still the same problem but i can view my inner pages of my website in mobile view ..
My error is " Fatal error: Call to undefined function aq_resize() in /home/ajaisandy/public_html/wp-content/plugins/js_composer/composer/lib/shortcodes/home_column_posts.php on line 223"
hence I place your aq resize php file inside "/home/ajaisandy/public_html/wp-content/plugins/js_composer/composer/lib/shortcodes/" but am still facing the same prob .. any solution .
thanks in advance
Hey mate
I notice that version 1.2 is still using the deprecated image_resize function.
Is this set to change in a coming version? The function was deprecated in 3.5, so I assume it will be on it's way out in an imminent release.
Cheers
Hey there,
first of all, great work with this script, we use it a lot and it works very well.
said so, image_resize on line 74 can also return a WP_Error object instead of a string, when the value is passed to str_replace on next line, page execution halts due the following error.
Catchable fatal error: Object of class WP_Error could not be converted to string
It happens, for instance, if user doesn't have GD extension installed. You could detect the WP_Error and just return original image url in this case. User wouldn't get a resized image but, at least, page would be displayed.
Here is the lovely new error: image_resize is deprecated since version 3.5! Use wp_get_image_editor()
Fix is explained here: http://make.wordpress.org/core/2012/12/06/wp_image_editor-is-incoming/ - I'm not sure how to do a pull-request as I haven't done that before.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.