Giter Club home page Giter Club logo

aqua-resizer's Introduction

Version 1.2

This small script will allow you to resize & crop WordPress images uploaded via the media uploader on the fly. It relies on WP's native functions to resize the images, and checks if there is an already resized version of the image so that it won't be wasting your server's resources to regenerate the images.

Why use it?

There are a couple of image resizing scripts out there that already have this function. Some authors simply use the add_image_size() function to define custom image sizes that will be generated for each image uploaded via the media uploader. I mostly find these methods somewhat a little complicated to use, or having some limitations or too resource intensive.

With Aqua Resizer, the only required inputs are the URL and width. It's easy, fast & efficient. Additionally, you have the additional options such as the height, crop, and array return.

How to use

Simply copy aq_resizer.php into your theme and reference it from your functions.php file e.g. require_once('aq_resizer.php');, then you're good to go.

You can then use it in your theme as such:

aq_resize($img_url,$width);

More usage instructions and examples can be found in our wiki

License

WTFPL

Do whatever you want with it. A linkback would be nice :)

Donations

If you have some spare bucks, please seriously consider helping the World Food Programme to build world without hunger. Your donations will provide foods & shelters to those who needs them the most! - Fill the Cup!

Or, buy me a coffee :)

Contacts

Twitter: http://twitter.com/syamilmj

Website: http://aquagraphite.com

Changelog

v1.2.1

  • WPML fix for image issue when Different domain per language is selected - #61

v1.2.0

  • Aqua Resize is now basically a class (still with a wrapper function so usage has not changed at all)
  • class written as Singleton pattern
  • removed fallback for WP older v3.5

v1.1.7

  • either $width or $height is required
  • return false if the image can not be resized to the exact dimension specified in the arguments in crop mode
  • return the original image if specified dimension is the same as the one of the original image

v1.1.6

  • uses wp_get_image_editor() (WP3.5)

v1.1.5

  • handles wp_error
  • shorten script

v1.1.4

  • fix for compatibility with wpml

v1.1.3

  • array return use int (0,1,2)

v1.1.2

  • add check for broken image

v1.1.1

  • default $single to true and return string

v1.1

  • fix issue with smaller widths

v1.0 first commit

aqua-resizer's People

Contributors

alsaydi avatar awps avatar chriseverson avatar claudiosanches avatar javiertury avatar mxmzb avatar syamilmj avatar totpero avatar vukvukovich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aqua-resizer's Issues

site in subdomain - images not showing

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 wont 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

Aqua Resizer not resizing all images available on the staging server but works perfect in localhost

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;

V1.2 using deprecated WP function

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

Tried adding the php page in my website but still facing the same problem

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

Images not working on SSL with https

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?

Images not sharp

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!
home
portfolio

Anneleen

Is it possible to outputing feature image or first post image as thumbnail?

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.

Bug with WPML

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".

No output for 755 file permission

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

Problem with unlimited image height

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 ?

Smaller images than specified don't show?

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

Issue #13 revisited

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

Image metadata and retina display support

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

local url check does not work with wpml set to use a directory per language

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.

Images not in upload folder

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.

Suggestion

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?

Not resizing get_post_gallery_images()

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.

Crop position

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

Deleting Aqua Resized Imgs (request)

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 ;)

Pixelated Images

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.

Not working Heroku

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.

Add filters on the returns

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!

Retina Support - Generating an @2x image for retina.js

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/

How to use with the SMOF Media Uploader?

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

check my code

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?

Test for images fitting the required measures is wrong.

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 ) ) ) {

AquaResizer does not work

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.

Remove cropping but enable resizing ?

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 !

Check for WP_Error

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.

Amazon S3 ?

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!

Where is version 1.2?

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?

Deleting generated files

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

JetPack Photon compatibility

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?

Amazon S3 ?

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

Deleting images from WP Admin

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.

Aqua-Resizer vs. WordPress thumbnails regarding thumb regeneration, tracking and retina support

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.

Parameter Checking Not Correct

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.

Feature requests

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

URL image source problem

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.