In my application I utilize TCPDF to create a PDF that pastes an SVG onto it with the $link being a url that is being provided by the user so the SVG on the PDF is clickable like this
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, $pageLayout, true, 'UTF-8', false);
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set margins
$pdf->SetMargins(0, 0, 0);
$pdf->SetXY(0, 0);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 0);
// set image scale factor
$pdf->setImageScale(1);
// add a page
$pdf->AddPage();
$fullPath = "$path".'qr-code/'."$uniqname".'.svg';
// Paste SVG onto page
$pdf->ImageSVG($file=$fullPath, $x=0, $y=0, $w='', $h='', $link=$query, $align='', $palign='', $border=0, $fitonpage=true);
/* Save as File */
$pdf->Output($path.'temp/'.$uniqname.'.pdf', 'F');
I then turn this PDF into a fully black CMYK PDF using Ghostscript
$targetFile = $path.'temp/'.$uniqname.'.pdf';
$iccFile = $this->params->get('ICC_FILE');
$process = new Process(['gs', '-o', $path.'pdf/'.$uniqname.'.pdf', '-sDEVICE=pdfwrite', '-sColorConversionStrategy=Gray', '-dProcessColorModel=/DeviceGray', '-dCompatibilityLevel=1.4', '-dOverrideICC=true', "-sDefaultCMYKProfile=$iccFile", $targetFile]);
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
And at the end I merge this PDF with another containing a Logo using FDPI like so
// create second PDF document for pasting logo
$pdf = new \setasign\Fpdi\Tcpdf\Fpdi(PDF_PAGE_ORIENTATION, PDF_UNIT, $pageLayout, true, 'UTF-8', false);
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set margins
$pdf->SetMargins(0, 0, 0);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 0);
// set image scale factor
$pdf->setImageScale(1);
// add a page
$pdf->AddPage();
/* Import fullHeight page */
$pages = $pdf->setSourceFile( $path.'pdf/'.$uniqname.'.pdf', 'F' );
$page = $pdf->ImportPage( 1 );
$pdf->useTemplate( $page, 0, 0 );
if($logoselect == 'eng')
{
$logos = $pdf->setSourceFile( $path.'img/engadin_online_CMYK.pdf', 'F' );
$logo = $pdf->ImportPage( 1 );
$pdf->useTemplate( $logo, 34.25, 33.75, null, 32.5);
}
if($logoselect == 'gam')
{
$logos = $pdf->setSourceFile( $path.'img/gammetermedia_CMYK.pdf', 'F' );
$logo = $pdf->ImportPage( 1 );
$pdf->useTemplate( $logo, 34.25, 33.75, null, 32.5);
}
// Close and output PDF document
$base = $pdf->Output('qrcode.pdf', 'E');
My problem now is that the link I created on the SVG of the first PDF is not in the last PDF anymore. Is there any way I can preserve this link so that it is still clickable in the last PDF or any other way I can achieve the same result?
As requested heres the initial pdf, the ghostscript output, and the final pdf
Related
This function can resize image when we upload at add new post and publish. When I try to use any import CSV plugin (Ultimate CSV Importer) for create multiple post and put my image url from other website, this function will not resize the image.
Can someone help to modified this function so can resize image during import?
// Hook the function to the upload handler
// https://developer.wordpress.org/reference/hooks/wp_handle_upload/
add_filter('wp_handle_upload', 'resize_image_after_upload');
function resize_image_after_upload($image_data){
// Set to null to disable that width/height resizing
$max_width = 800;
$max_height = 800;
// Check if there is a valid file
if(empty($image_data['file']) || empty($image_data['type'])) {
return $image_data;
}
// NOTE: We are not resizing any gifs, to avoid resizing animated gifs
// (which I think is the most common gif nowadays)
$valid_types = array('image/png','image/jpeg','image/jpg', 'image/webp');
if(!in_array($image_data['type'], $valid_types)) {
return $image_data;
}
// Get image image_editor
// https://developer.wordpress.org/reference/classes/wp_image_editor/
$image_editor = wp_get_image_editor($image_data['file']);
if(is_wp_error($image_editor)) {
return $image_data;
}
// Check if the image editor supports the image type
if(!$image_editor->supports_mime_type($image_data['type'])) {
return $image_data;
}
// Perform resizing
$sizes = $image_editor->get_size();
if((isset($sizes['width']) && $sizes['width'] > $max_width)
|| (isset($sizes['height']) && $sizes['height'] > $max_height)) {
// Resize, but do not crop
$image_editor->resize($max_width, $max_height, false);
// We will use the default recommended image quality
// Change, if you want to set a custom quality
//$image_editor->set_quality(90);
$image_editor->save($image_data['file']);
}
return $image_data;
}
i would like to implement the tcpdf in my wordpress project. I tried to call below example tcpdf file (it's an example from tcpdf), unfortunately its output are crazy code as below,
%PDF-1.7 %���� 8 0 obj << /Type /Page /Parent 1 0 R /LastModified (D:20180829011846+00'00') /Resources 2 0 R /MediaBox.....
I have no idea what's the problem of this, many many thanks if any guidance to me, thank you very much.
<?php
// Include the main TCPDF library (search for installation path).
require_once(dirname(__FILE__).'/tcpdf/examples/tcpdf_include.php');
ob_end_clean();
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 038');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 038', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (#file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('helvetica', '', 20);
// add a page
$pdf->AddPage();
$txt = 'Example of CID-0 CJK unembedded font.
To display extended text you must have CJK fonts installed for your PDF reader:';
$pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);
// set font
$pdf->SetFont('cid0jp', '', 40);
$txt = 'こんにちは世界';
$pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_038.pdf', 'I');
?>
In the pdf output method, try 'F' as the second argument instead of 'I'.
$pdf->Output('example_038.pdf', 'F');
I am using the Winnovative's PdfConverter to convert my HTML page to a PDF, i am able to get the PDF with header footer and all. But i have a requirement where i need to set the height of the Header and footer dynamically based on the content of the text that needs to be added. Below is the code i tried to achieve this but was not successful. Please can you help on what would i be missing here, or is there any other method i need to follow.
The PdfFooterOptions.FooterHeight is initially set to default 40px.
PdfConverter pdfConverter = new PdfConverter();
// set the converter options
pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
pdfConverter.PdfDocumentOptions.PdfPageOrientation = PdfPageOrientation.Portrait;
// set header and footer
pdfConverter.PdfDocumentOptions.ShowHeader = true;
pdfConverter.PdfDocumentOptions.ShowFooter = true;
//Add header and footer text
AddHeaderElements(pdfConverter, text);
AddFooterElements(pdfConverter, text);
// set the HTML content
pdfConverter.PdfDocumentOptions.FitWidth = true;
// set the embedded fonts option
pdfConverter.PdfDocumentOptions.EmbedFonts = true;
// set the live HTTP links option
pdfConverter.PdfDocumentOptions.LiveUrlsEnabled = true;
// set the JavaScript
pdfConverter.JavaScriptEnabled = true;
// set the images in PDF are compressed with JPEG to reduce the PDF document size
pdfConverter.PdfDocumentOptions.JpegCompressionEnabled = true;
// enable auto-generated bookmarks for a specified list of tags (e.g. H1 and H2)
pdfConverter.PdfBookmarkOptions.HtmlElementSelectors = new string[] { "H1", "H2" };
// Performs the conversion and get the pdf document bytes that can be further
// saved to a file or sent as response to browser
// The baseURL parameter helps the converter to get the CSS files and images
// referenced by a relative URL in the HTML string.
byte[] pdfValue = null;
pdfValue = pdfConverter.GetPdfBytesFromHtmlString(htmlCodeToConvert);
private void AddFooterElements(PdfConverter pdfConverter, string title)
{
//write the page number
TextElement footerText = new TextElement(550, pdfConverter.PdfFooterOptions.FooterHeight - 20,
string.Format(uiContentController.GetText("Aanvarag_Page"), "&p;", "&P;"),
new System.Drawing.Font(new System.Drawing.FontFamily("Tahoma"),
7, System.Drawing.GraphicsUnit.Point));
footerText.EmbedSysFont = true;
footerText.TextAlign = HorizontalTextAlign.Left;
pdfConverter.PdfFooterOptions.AddElement(footerText);
// set the footer HTML area
HtmlToPdfElement footerHtml = new HtmlToPdfElement(10, 0, 0,
0,
title, null, 1024, 0);
footerHtml.NavigationCompletedEvent += OnFooterHtmlNavigationCompleted;
pdfConverter.PdfFooterOptions.AddElement(footerHtml);
}
void OnFooterHtmlNavigationCompleted(NavigationCompletedParams eventParams)
{
// Get the header HTML width and height from event parameters
float footerHtmlWidth = eventParams.HtmlContentWidthPt;
float footerHtmlHeight = eventParams.HtmlContentHeightPt;
// Calculate the header width from coverter settings
float footerWidth = pdfConverter.PdfDocumentOptions.PdfPageSize.Width - pdfConverter.PdfDocumentOptions.LeftMargin -
pdfConverter.PdfDocumentOptions.RightMargin;
// Calculate a resize factor to fit the header width
float resizeFactor = 1;
if (footerHtmlWidth > footerWidth)
resizeFactor = footerWidth / footerHtmlWidth;
// Calculate the header height to preserve the HTML aspect ratio
float footerHeight = footerHtmlHeight * resizeFactor;
// Set the calculated header height
pdfConverter.PdfFooterOptions.FooterHeight = footerHeight;
}
There is a working example with source code for headers. For footers should be similar.
// Define the HTML to PDF converter object as a class member to make it accessible in the headerHtml_NavigationCompletedEvent handler
// where the header height will be automatically adjusted
private HtmlToPdfConverter htmlToPdfConverter;
// Indicates if a line should be drawn at the botom of the header
private bool drawHeaderLine = true;
protected void convertToPdfButton_Click(object sender, EventArgs e)
{
// Create a HTML to PDF converter object with default settings
htmlToPdfConverter = new HtmlToPdfConverter();
// Set license key received after purchase to use the converter in licensed mode
// Leave it not set to use the converter in demo mode
htmlToPdfConverter.LicenseKey = "fvDh8eDx4fHg4P/h8eLg/+Dj/+jo6Og=";
// Enable header in the generated PDF document
htmlToPdfConverter.PdfDocumentOptions.ShowHeader = true;
string headerHtmlUrl = Server.MapPath("~/DemoAppFiles/Input/HTML_Files/Header_HTML.html");
Document documentObject = null;
try
{
if (autoResizeHeaderRadioButton.Checked)
{
// Create a HTML element to be added in header
HtmlToPdfElement headerHtml = new HtmlToPdfElement(headerHtmlUrl);
// Install a handler where to set the automatically calculated header height
headerHtml.NavigationCompletedEvent += new NavigationCompletedDelegate(headerHtml_NavigationCompletedEvent);
// Add the HTML element to header
// When the element is rendered in header by converter, the headerHtml_NavigationCompletedEvent handler
// will be invoked and the header height will be automatically calculated
htmlToPdfConverter.PdfHeaderOptions.AddElement(headerHtml);
// Call the converter to produce a Document object
documentObject = htmlToPdfConverter.ConvertUrlToPdfDocumentObject(urlTextBox.Text);
// Uninstall the handler
headerHtml.NavigationCompletedEvent -= new NavigationCompletedDelegate(headerHtml_NavigationCompletedEvent);
// Draw a line at the header bottom
if (drawHeaderLine)
{
float headerWidth = documentObject.Header.Width;
float headerHeight = documentObject.Header.Height;
// Create a line element for the bottom of the header
LineElement headerLine = new LineElement(0, headerHeight - 1, headerWidth, headerHeight - 1);
// Set line color
headerLine.ForeColor = Color.Gray;
// Add line element to the bottom of the header
documentObject.Header.AddElement(headerLine);
}
// Save the PDF document in a memory buffer
byte[] outPdfBuffer = documentObject.Save();
// Send the PDF as response to browser
// Set response content type
Response.AddHeader("Content-Type", "application/pdf");
// Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Auto_Resize_Header_Footer.pdf; size={0}", outPdfBuffer.Length.ToString()));
// Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer);
// End the HTTP response and stop the current page processing
Response.End();
}
else
{
// Create a HTML to PDF element to be added in header
HtmlToPdfElement headerHtml = new HtmlToPdfElement(headerHtmlUrl);
// Set a fixed header height in points
htmlToPdfConverter.PdfHeaderOptions.HeaderHeight = float.Parse(headerHeightTextBox.Text);
// Set the HTML element to fit the container height
headerHtml.FitHeight = true;
// Add HTML element to fit the fixed header height
htmlToPdfConverter.PdfHeaderOptions.AddElement(headerHtml);
// Draw a line at the header bottom
if (drawHeaderLine)
{
// Calculate the header width based on PDF page size and margins
float headerWidth = htmlToPdfConverter.PdfDocumentOptions.PdfPageSize.Width -
htmlToPdfConverter.PdfDocumentOptions.LeftMargin - htmlToPdfConverter.PdfDocumentOptions.RightMargin;
// Calculate header height
float headerHeight = htmlToPdfConverter.PdfHeaderOptions.HeaderHeight;
// Create a line element for the bottom of the header
LineElement headerLine = new LineElement(0, headerHeight - 1, headerWidth, headerHeight - 1);
// Set line color
headerLine.ForeColor = Color.Gray;
// Add line element to the bottom of the header
htmlToPdfConverter.PdfHeaderOptions.AddElement(headerLine);
}
// Convert the HTML page to a PDF document in a memory buffer
byte[] outPdfBuffer = htmlToPdfConverter.ConvertUrl(urlTextBox.Text);
// Send the PDF as response to browser
// Set response content type
Response.AddHeader("Content-Type", "application/pdf");
// Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Auto_Resize_Header_Footer.pdf; size={0}", outPdfBuffer.Length.ToString()));
// Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer);
// End the HTTP response and stop the current page processing
Response.End();
}
}
finally
{
// Close the PDF document
if (documentObject != null)
documentObject.Close();
}
}
/// <summary>
/// This handler is called after the navigation to header HTML completed. The document header is resized in this event handler
/// </summary>
/// <param name="eventParams">The event parameter containing the HTML content size in pixels and points</param>
void headerHtml_NavigationCompletedEvent(NavigationCompletedParams eventParams)
{
// Get the header HTML width and height from event parameters
float headerHtmlWidth = eventParams.HtmlContentWidthPt;
float headerHtmlHeight = eventParams.HtmlContentHeightPt;
// Calculate the header width from coverter settings
float headerWidth = htmlToPdfConverter.PdfDocumentOptions.PdfPageSize.Width - htmlToPdfConverter.PdfDocumentOptions.LeftMargin -
htmlToPdfConverter.PdfDocumentOptions.RightMargin;
// Calculate a resize factor to fit the header width
float resizeFactor = 1;
if (headerHtmlWidth > headerWidth)
resizeFactor = headerWidth / headerHtmlWidth;
// Calculate the header height to preserve the HTML aspect ratio
float headerHeight = headerHtmlHeight * resizeFactor;
if (!(headerHeight < htmlToPdfConverter.PdfDocumentOptions.PdfPageSize.Height - htmlToPdfConverter.PdfDocumentOptions.TopMargin -
htmlToPdfConverter.PdfDocumentOptions.BottomMargin))
{
throw new Exception("The header height cannot be bigger than PDF page height");
}
// Set the calculated header height
htmlToPdfConverter.PdfDocumentOptions.DocumentObject.Header.Height = headerHeight;
}
Im using the following code at functions.php to resize my IFRAMES
function add_youtube_size($youtubehtml) {
if (strpos($youtubehtml, "<iframe" ) !== false) {
$youtubesearch = array( 'width="460"', 'height="310"');
$youtubereplace = array( 'width="600"', 'height="338"');
$youtubehtml = str_replace($youtubesearch, $youtubereplace, $youtubehtml);
return $youtubehtml;
} else {
return $youtubehtml;
}
}
add_filter('the_content', 'add_youtube_size', 10);
But this code only edit the size of iframes with 460 x 310.
There Is any way i can change that line $youtube search = array( 'width="460"', 'height="310"'); to get any possible sizes?
Yes you can change it
$youtubesearch = array( 'width="460"', 'height="310"');
$youtubereplace = array( 'width="600"', 'height="338"');
In those lines change both width and height to what you need but it important that your search video also should available in your written width and height
I would like to do some custom processing on a certain thumbnail size in Wordpress with ImageMagick beyond the normal Wordpress functionality and am not quite sure how to go about doing this.
So I add my new thumbnail size:
add_image_size( 'new-thumb', 100, 100 );
And then this is where I'm not sure where I should hook into. Before the final copy of the thumbnail is saved within Wordpress I want to do some custom processing on it. Basic psuedo code for what I want is:
The_hook_or_action_that_fires_when_a_thumbnail_is_saved() {
if (<Thumbnail Being Generated> == 'new-thumb') {
$thumb_file = 'the thumbnail image we are about to save';
$thumbfile = 'do some imagemagic stuff here';
}
save_thumbnail;
}
I can handle the imagemagick stuff, but I'm not sure how / where to hook this custom thumbnail processing into.
Any advise would be greatly appreciated!
Thanks #brasofilo for pointing me in the right direction...
I poked around a bit and figured this one out. You can hook into wp_generate_attachment_metadata and do some image manipulation.
The basics of what I was trying to do is resize an image to a specific size ("brands" thumbnail), then expand the canvas for that thumbnail to a static height and width with a white background.
In case anyone has a similar situation I thought I would paste some code. It could be cleaned up to remove the repletion for each image type. The one issue with this code is that if the original image size is less than the desired thumbnail size it will not be generated (which is WordPress functionality).
add_image_size( 'brands', 200, 168 );
add_filter('wp_generate_attachment_metadata','replace_uploaded_image');
function replace_uploaded_image($image_data) {
// if there is no brands image : return
if ( !isset($image_data['sizes']['brands']) )
return $image_data;
//Set our desired static height / width (200px * 168px)
$staticWidth = 200;
$staticHeight = 168;
// paths to the uploaded image and the large image
$upload_dir = wp_upload_dir();
$brands_image_location = $upload_dir['path'] . '/' . $image_data['sizes']['brands']['file'];
// set our temp image file
$brands_image_location_tmp = "$brands_image_location.tmp";
// get the attributes of the source image
list($imageWidth, $imageHeight, $imageType, $imageAttr) = getimagesize($brands_image_location);
// there are different php functions depending on what type of image it is, so check the type
switch($imageType) {
//GIF
case 1:
//Create a 200x168 white canvas
$newimage=imagecreatetruecolor($staticWidth,$staticHeight);
$white=imagecolorallocate($newimage, 255, 255, 255);
imagefill($newimage,0,0,$white);
//Calculate where the image should start so its centered
if($imageWidth == $staticWidth) { $x_pos = 0; } else { $x_pos = round( ($staticWidth - $imageWidth) / 2 ); }
if($imageHeight == $staticHeight) { $y_pos = 0; } else { $y_pos = round( ($staticHeight - $imageHeight) / 2 ); }
//Copy the source image to the new canvas
$src = imagecreatefromgif($brands_image_location);
imagecopy($newimage, $src, $x_pos, $y_pos, 0, 0, $imageWidth, $imageHeight);
imagegif($newimage,$brands_image_location_tmp);
// delete the uploaded image
unlink($brands_image_location);
// rename the temporary brands image
rename($brands_image_location_tmp, $brands_image_location);
// update image metadata and return them
$image_data['sizes']['brands']['width'] = $staticWidth;
$image_data['sizes']['brands']['height'] = $staticHeight;
break;
//JPG
case 2:
//Create a 200x168 white canvas
$newimage=imagecreatetruecolor($staticWidth,$staticHeight);
$white=imagecolorallocate($newimage, 255, 255, 255);
imagefill($newimage,0,0,$white);
//Calculate where the image should start so its centered
if($imageWidth == $staticWidth) { $x_pos = 0; } else { $x_pos = round( ($staticWidth - $imageWidth) / 2 ); }
if($imageHeight == $staticHeight) { $y_pos = 0; } else { $y_pos = round( ($staticHeight - $imageHeight) / 2 ); }
//Copy the source image to the new canvas
$src = imagecreatefromjpeg($brands_image_location);
imagecopy($newimage, $src, $x_pos, $y_pos, 0, 0, $imageWidth, $imageHeight);
imagejpeg($newimage,$brands_image_location_tmp);
// delete the uploaded image
unlink($brands_image_location);
// rename the temporary brands image
rename($brands_image_location_tmp, $brands_image_location);
// update image metadata and return them
$image_data['sizes']['brands']['width'] = $staticWidth;
$image_data['sizes']['brands']['height'] = $staticHeight;
break;
//PNG
case 3:
//Create a 200x168 white canvas
$newimage=imagecreatetruecolor($staticWidth,$staticHeight);
$white=imagecolorallocate($newimage, 255, 255, 255);
imagefill($newimage,0,0,$white);
//Calculate where the image should start so its centered
if($imageWidth == $staticWidth) { $x_pos = 0; } else { $x_pos = round( ($staticWidth - $imageWidth) / 2 ); }
if($imageHeight == $staticHeight) { $y_pos = 0; } else { $y_pos = round( ($staticHeight - $imageHeight) / 2 ); }
//Copy the source image to the new canvas
$src = imagecreatefrompng($brands_image_location);
imagecopy($newimage, $src, $x_pos, $y_pos, 0, 0, $imageWidth, $imageHeight);
imagepng($newimage,$brands_image_location_tmp);
// delete the uploaded image
unlink($brands_image_location);
// rename the temporary brands image
rename($brands_image_location_tmp, $brands_image_location);
// update image metadata and return them
$image_data['sizes']['brands']['width'] = $staticWidth;
$image_data['sizes']['brands']['height'] = $staticHeight;
break;
}
return $image_data;
}
In my library I have the following:
Set custom name for generated thumbnails
Very interesting manipulation of thumb names and crop. Check the original Q&A linked in this one.
Uses:
intermediate_image_sizes_advanced
wp_generate_attachment_metadata
Automatically Use Resized Images Instead Of Originals
Uses:
wp_generate_attachment_metadata
How to automatically add rounded corners to thumbnails?
Uses:
image_make_intermediate_size and L#432
How to Require a Minimum Image Dimension for Uploading?
Uses:
wp_handle_upload_prefilter
Organize uploads by year, month and day
Uses:
wp_handle_upload_prefilter
wp_handle_upload and L#466
upload_dir
I would like to suggesta change, in order to make it work with Thumbnails Regenerate Plugin
$upload_dir = wp_upload_dir();
$brands_image_location = $upload_dir['basedir'].'/'.dirname($image_data['file']) . '/' . $image_data['sizes']['brands']['file'];
$brands_image_location = $brands_image_location.'.tmp';
That's so because wp_upload_dir returns the path for the current year-month but some previously uploaded images could have different path.